SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: Alter class with JS... How to...
-
Dec 26, 2006, 06:22 #1
Alter class with JS... How to...
Ok, I have this script here:
var temp;
function abrediv(id){
if(temp != undefined){
if( document.getElementById("div_"+id).style.display == "none"){
// +
document.getElementById("div_"+temp).style.display = "none";
document.getElementById("img_"+temp).src = "img/plus.jpg";
// -
document.getElementById("div_"+id).style.display = "block";
document.getElementById("img_"+id).src = "img/minus.jpg";
And in the html, it is used like this:
<a href="javascript:abrediv('1');" class="menuItem_0"><img id="img_1" src="img/plus.jpg" width="9" height="9" border="0"> Menu Item</a>
Now, the script only changes the image and the display (block or none), now how can I add a class change? Like when the display is set to block, assign one class to the anchor and when is set to none, assign a different one?
I'm not big in js, that is why I need help, actually not big would be an understatement, I'm terrible....
Thanks anyway....
-
Dec 26, 2006, 13:05 #2
- Join Date
- Sep 2005
- Location
- Tanzania
- Posts
- 4,662
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Code:var temp; function abrediv(id){ if (temp != undefined){ if (document.getElementById("div_"+id).style.display == "none") { document.getElementById("div_"+temp).style.display = "none"; document.getElementById("img_"+temp).src = "img/plus.jpg"; document.getElementById("div_"+id).style.display = "block"; document.getElementById("img_"+id).src = "img/minus.jpg"; document.getElementById("a_"+id).className = "newclass"; } } }
Code:<a href="#" class="menuItem_0" id="a_1" onclick="abrediv('1');"><img id="img_1" src="img/plus.jpg" width="9" height="9" border="0"> Menu Item</a>
Bookmarks