[thelist] DOM - change an element's class

Adriano Castro ad at netvisao.pt
Thu Apr 1 05:17:39 CST 2004


Nevermind that...

I got it!

function change(id, newClass) {
    identity=document.getElementById(id);
    identity.className=newClass;
}

That oughta work!
Let me give it a try...


>     Consider the following:
>
> + HTML
> --------
> <li><a onmouseover="javascript: changeBorder('subtabs','FC7713');"
> onmouseout="javascript: changeBorder('subtabs','D3D9DE');">BARFOO</a></li>
>
> <div id="subtabs" name="subtabs" class="inactive">FOOBAR</div>
> --------
>
>
> + STYLE
> --------
> #subtabs.inactive {border: 1px solid #D3D9DE;}
>
> #subtabs.active { border: 1px solid #FC7713;}
> --------
>
>
> + JAVASCRIPT
> --------
> function changeBorder(area_id,color_code) {
>     area_to_modify = document.getElementById(area_id);
>     area_to_modify.style.borderColor = "#"+color_code;
> }
> --------
>
>
>     That works perfectly! Now forget all about it and tell me how can I
> change "subtabs" class from ".inactive" to ".active" instead of
> directly changing the bordercolor property.
>
>
>     AD
> --
> www.adrianocastro.net/freeculture/
> "shouldn't it be easier still?"


More information about the thelist mailing list