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

  • Home
  • SEARCH
  • 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 8092585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:19:02+00:00 2026-06-05T20:19:02+00:00

Markup: <ul> <li><a href=# class=item-list data-id=1>Link 1</a></li> <li><a href=# class=item-list data-id=2>Link 2</a></li> <li><a href=#

  • 0

Markup:

<ul>
<li><a href="#" class="item-list" data-id="1">Link 1</a></li>
<li><a href="#" class="item-list" data-id="2">Link 2</a></li>
<li><a href="#" class="item-list" data-id="3">Link 3</a></li>
</ul>

In JQuery, i would select link 1 and it should be able to fetch the data-id of link1. I tried

$('.item-list').click(function(){
 var link = $(this);
 alert($(this).data('id'));
});

It doesn’t have any result.

Oh. the list gets generated after the page is loaded. I am querying the DB to get the list. Also, it is also possible for the list to change, depending on how the user filters the dB.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 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-06-05T20:19:03+00:00Added an answer on June 5, 2026 at 8:19 pm

    If the list is generated after the page is loaded, the .click binding might not work. Maybe you can try .live, like so:

    $('.item-list').live('click', function(){
       var link = $(this);
       alert($(this).data('id'));
    });
    

    EDIT:

    What I always seem to forget 🙂 as of jQuery 1.7, .live() is deprecated. You should use .on() like so:

     $("body").on("click",".item-list",function(){
        var link = $(this);
        alert($(this).data('id'));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my markup: <ul class=tab1> <li><a href=http://site.com/some.html?param=1></li> <li><a href=http://site.com/some.html?param=2></li> <li><a href=http://site.com/some.html?param=3></li> ... </ul>
I have an href image in this markup. <div class=imgdiv> <a class=imga href=http://destination.com> <img
I have this type of markup: <div class=box href=pic-gallery/img01.jpg> <div>----------</div> </div> Now as I
I would like to bind the same event to a list of anchor link.
I have this href defined in my markup: foreach (Car car in Model.Cars) {
The markup below is used for my jQuery carousel widget. The first div serves
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
I have some markup similar to the following: <select> <option selected=selected>Apple</option> <option selected=>Orange</option> </select>
I have the following markup, <ul id=menu> <li><a href=#>Something1</a></li> <li><a href=#>Something2</a></li> <li><a href=#>Something3</a></li> <li><a
Imagine the following markup: <a href=#link01>1</a> <a href=#link02>2</a> And: $('a').click(function(){ var href = $(location).attr('href'),

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.