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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically changing the class of an element

Status
Not open for further replies.

arundahar

Programmer
Apr 27, 2001
53
GB
I have 2 frames on my page. How do i change the "class" of an element using javascript?

Thanks

A.
 
hmm, what i actually meant is to change this :

class='Show' to class='Hide'

rather than the actual className itself..

Doesn't there have to be a document. before your example?
 
<DIV id=ShowHideDiv>hello</DIV>
<a href=&quot;#&quot; onclick=&quot;ShowHide(); return false&quot;>Show/Hide</a>

Either Write (IE, N6):
<script language=javascript>
function ShowHide()
{
if (ShowHide.style.visibility==&quot;visible&quot;)
{
ShowHideDiv.style.visibility=&quot;hidden&quot;
}
else
{
ShowHideDiv.style.visibility=&quot;hidden&quot;
}
}
</script>


or (IE):


<script language=javascript>
function ShowHide()
{
if (document.all[&quot;ShowHideDiv&quot;].style.visibility==&quot;visible&quot;)
{
document.all[&quot;ShowHideDiv&quot;].style.visibility=&quot;hidden&quot;
}
else
{
document.all[&quot;ShowHideDiv&quot;].style.visibility=&quot;hidden&quot;
}
}
</script>
 
<DIV id=ShowHideDiv>hello</DIV>
<a href=&quot;#&quot; onclick=&quot;ShowHide(); return false&quot;>Show/Hide</a>

Either Write (IE, N6):
<script language=javascript>
function ShowHide()
{
if (ShowHide.style.visibility==&quot;visible&quot;)
{
ShowHideDiv.style.visibility=&quot;hidden&quot;
}
else
{
ShowHideDiv.style.visibility=&quot;visible&quot;
}
}
</script>


or (IE):


<script language=javascript>
function ShowHide()
{
if (document.all[&quot;ShowHideDiv&quot;].style.visibility==&quot;visible&quot;)
{
document.all[&quot;ShowHideDiv&quot;].style.visibility=&quot;hidden&quot;
}
else
{
document.all[&quot;ShowHideDiv&quot;].style.visibility=&quot;visible&quot;
}
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top