How to get unique value in jquery?

Posted by jquerier on Stack Overflow See other posts from Stack Overflow or by jquerier
Published on 2010-05-21T08:49:39Z Indexed on 2010/05/21 8:50 UTC
Read the original article Hit count: 180

Filed under:
|
|
|

I am learning jquery.

I have following chunk of code in a html file:

<table width="100%"> 
<tr> 
    <td align='center'> 
        <div> 
            <a id='get_this' href='#'> 
            <input type='hidden' id='id' value='1'><img src='images/1.gif'></a> 
        </div> 
    </td> 
    <td align='center'> 
        <div> 
            <a id='get_this' href='#'> 
            <input type='hidden' id='id' value='2'><img src='images/2.gif'></a> 
        </div> 
    </td> 
    <td align='center'> 
        <div> 
            <a id='get_this' href='#'> 
            <input type='hidden' id='id' value='3'><img src='images/3.gif'></a> 
        </div> 
    </td> 
</tr> 

What I want to do is, when I click any of the image, I can get the value, so that I can display the information. For example, I click the id=1, then I will display information on id1 in somewhere else. I tried this:

$("a#get_this").click(function(){
        var id = $('input[type=hidden]#id').val();
        window.alert("You have chosen the id: " + id);
    });

It always return id: 1 to me.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about beginner