Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 798041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:54:28+00:00 2026-05-14T22:54:28+00:00

I am learning jQuery. I have the following chunk of code in an HTML

  • 0

I am learning jQuery.

I have the following chunk of code in an 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 <input hidden> 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.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:54:29+00:00Added an answer on May 14, 2026 at 10:54 pm

    IDs have to be unique in a HTML document. I think the behaviour is undefined if you have more than one element with the same ID, but most browser probably pick the first one then.

    Use classes instead:

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

    and JS:

    $("a.get_this").click(function(){
            // find all input elements inside "a" (which is only one)
            var id = $(this).find('input').val(); 
            window.alert("You have chosen the id: " + id);
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to program (while learning JQuery) the following: I have a form
As part of learning jQuery, I decided to do a simple tic-tac-toe game in
Beyond the official documentation, are there any recommended resources for learning to build jQuery
I'm learning JavaScript and while browsing through the jQuery library I see : (colon)
Where is a good place to get started learning how to use jQuery? It
I've just started learning Jquery but the examples aren't helping me much... Now whats
I'm trying to make a quick jquery plugin (as a learning exercise) for making
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
Learning a little about T-SQL, and thought an interesting exercise would be to generate
Learning from my last question , most member names seem to get included in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.