document.getElementById not working for <a> tag

Posted by Kartik on Stack Overflow See other posts from Stack Overflow or by Kartik
Published on 2010-03-18T11:28:30Z Indexed on 2010/03/18 11:31 UTC
Read the original article Hit count: 382

Filed under:
|
|
|

hi,

I'm very new to js so kindly help me with this.

I am trying to add a class to a tag using onClick.

The code is as shown below:

<a class="gkvSprite" href="#" id="123" onClick="showhide('1')">Click 1</a>
<a class="gkvSprite" href="#" id="456" onClick="showhide('2')">Click 2</a>
<a class="gkvSprite" href="#" id="789" onClick="showhide('3')">Click 3</a>

Now when i click i need to add a class called "selected" for the one i select. I tried using setAttribute and add class of jquery as well but was not successful

When i alert the document.getelementbyId(123) it gives out the link.

Can someone kindly help me?

Thanks in Advance
Alloi

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about getelementbyid