setAttribute, onClick and cross browser compatibility

onew.setAttribute(“type”, “button”); Never use setAttribute on HTML documents. IE gets it badly wrong in many cases, and the DOM-HTML properties are shorter, faster and easier to read: onew.type=”button”; onew.onclick = function(){fnDisplay_Computers(“‘” + alines[i] + “‘”); }; // ie What is ‘alines’? Why are you converting it to a string and surrounding it with single quotes? … Read more

setAttribute and video.src for changing video tag source not working in IE9

Great news, I found a true solution to switching/changing videos in HTML5 video tags via JavaScript without using the annoying hack I tried to explain! It’s unbelievably simple and it just took a LOT of experimenting with IE. Below is the code in its simplest form to work in IE: <html> <body> <video id=’videoPlayer’ width=”320″ … Read more

When to use setAttribute vs .attribute= in JavaScript?

From Javascript: The Definitive Guide, it clarifies things. It notes that HTMLElement objects of a HTML doc define JS properties that correspond to all standard HTML attributes. So you only need to use setAttribute for non-standard attributes. Example: node.className=”test”; // works node.frameborder=”0″; // doesn’t work – non standard attribute node.setAttribute(‘frameborder’, ‘0’); // works