How do I change the class of multiple divs at the same time using the "document.getElementsByTagName" function?
It seems like I can do everything but change the class of the objects defined with the "document.getElementsByTagName" function; I can display an alert stating how many objects are in that function, how many have a certain class...
but I cant seem to change the class!
I am using the following javascript to try and change the class:
my stylesheet:Code:function divc2(){ divi=document.getElementsByTagName('div'); divi.className='class1'; } function divc1(){ divi=document.getElementsByTagName('div'); divi.className='class2'; }
and the body of my test page is:Code:.class1{ color:#000fff; } .class2{ color:#5e5e5e; }
Is there something wrong with this code? It seems to me like it should do the job, but it doesn't. I'm using the FireBug extension for FireFox and that doesn't come up with any errors, so why doesn't it work?HTML Code:<div class="class1" id="div">Div1</div><div class="class1" id="div2">Div2</div> <a href="javascript:divc2()">Change To Class2</a> | <a href="javascript:divc1()">Change To Class1</a>
(My Test Page Is Located At http://dev.formulationx.com/dlinkt/)



Reply With Quote

Bookmarks