Forum Moderators: open

Message Too Old, No Replies

Change elements id value with JS?

How to change <li>'s id?

         

Tiibou

4:58 am on Jul 7, 2005 (gmt 0)



Hi!
Hope someone could help me with my problem. It is like this:

I've got a tabs made with <li>s' and I would like to show active tab with id=current like this:

<ul>
<li id="current"><a href="#">Home</a></li>
<li><a href="#" target="IFRAME">Abroad</a></li>
<li><a href="#" target="IFRAME">World</a></li>
</ul>

and when user clicks for example Abroad -link, id current would go to it's li. As you can see I'm not loading whole page when user clicks something because content is shown in ifame.

I put onClick="this.id='current'" to every <li> but then there will be multiple id=current, so somehow I should change id in <li>. In <li> there could be id=empty and then change these two states.

Thanks in advance!

Best regards,
Tiibou

orhor

6:26 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



put onClick='myFunction(this);' on every <li> and id='myUL' on <ul>

function myFunction(element){
liArray=document.getElementById("myUL").childNodes;
i=0;
while(liArray[i]){
liArray[i].id="";
i++;
}
element.id="current";
}


<ul id='myUL'>
<li onClick='myFunction(this);'><a href="#">Home</a></li>
<li onClick='myFunction(this);'><a href="#">Abroad</a></li>
<li onClick='myFunction(this);'><a href="#">World</a></li>
</ul>