Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

className in NS6 1

Status
Not open for further replies.

theocraticmind

Programmer
Apr 19, 2002
318
0
0
CA
how do i change the class name of a div in NS6?
 
I didn't try it but I am guessing...

document.getElementById("mydiv").class = "new class name";

===
Supports Mozilla and Web Standards
Knows HTML/XHTML, CSS1, JavaScript, PHP, C++, DOM1
===
 
document.getElementById("mydiv").className = "new class name";

if that don't work.

document.getElementById("mydiv").setAttribute("class","new class name");

Hope this helps. Gary Haran
 
no, and no. here is my test code so you know it's not my fault:

<style>
.class1 {font-size:40px}
.class2 {font-size:10px}
</style>
<script>
document.getElementById(&quot;mydiv&quot;).setAttribute(&quot;class&quot;,&quot;class2&quot;); //here is where i tried the other ways as well.
</script>
<div class=&quot;class1&quot; id=&quot;mydiv&quot;>fggeergreterg</div>
 
ok, i apologise. after swiming through devedge (netscape's developer site) className turns out to be correct. question though, why dose my code not work?
 
The flow of a document is from top to bottom. With that example you just showed the javascript tries to access a thing that does not yet exist.

try calling the JS code after the div is loaded :

<style>
.class1 {font-size:40px}
.class2 {font-size:10px}
</style>

<div class=&quot;class1&quot; id=&quot;mydiv&quot;>fggeergreterg</div>

<script>
document.getElementById(&quot;mydiv&quot;).setAttribute(&quot;class&quot;,&quot;class2&quot;); //here is where i tried the other ways as well.
</script>

Hope this helps. Gary Haran
 
heh, you think i would have caught somthing so basic myself...thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top