Random JavaScript Comment
Just throwing this out there...
Does it ever bug anyone that when you need to change an attribute of an HTML tag in JavaScript you have to figure out which of the following ways will work across all the browsers for the particular element attribute you're working with? (Does it ever bug anyone that I use run-on sentences? ;) ).
Does it ever bug anyone that when you need to change an attribute of an HTML tag in JavaScript you have to figure out which of the following ways will work across all the browsers for the particular element attribute you're working with? (Does it ever bug anyone that I use run-on sentences? ;) ).
- this.element.setAttribute("width", "100") [Generic setter method call.]
- this.element.style.display = "inline" [Direct access to attribute.]
- this.element.id = "someId" [Direct access to attribute.]
- this.element.className = "someClassName" [Direct access to attribute, but you have to append "Name" to "class".]

1 Comments:
Hi Collin,
No, tonight I wrote a little code that used one of the above methods. It got me thinking about the JS I was writing on my PM app and how I struggled to get it all straight (which method to use for which attribute).
I remember spending a lot of time dealing with the .className one. For the life of me I couldn't figure out why I could do:
element.id = "whatever"
but to change "class" it had to be:
element.className = "whatever"
If we only had to develop for 1 browser, JS would be sweat! It's usually pretty lightweight on the client (each browser is faster using different methods of page manipulation), but dealing with multiple runtimes is a pain!
Post a Comment
Subscribe to Post Comments [Atom]
<< Home