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 have been learning css & jquery. <!DOCTYPE html> <html> <head> <style type=text/css> #box
Learning jquery, so please be kind :) Using PHP, I have a table with
I am trying to program (while learning JQuery) the following: I have a form
For learning jQuery UI dialog, I have the code defined below. I need to
So I'm learning jQuery Mobile and I'm trying to run the following code below
I'm learning JQuery and have found the factory function $() with its selectors quite
Sorry guys, didn't know how to word this one. Still learning jquery and have
I've recently been learning jQuery Mobile but have a hard time remembering all the
Hi I am learning JQuery and I have written a small function where I
I have just started learning Jquery and am new to writing javascript (I am

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.