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 9259801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:44:39+00:00 2026-06-18T12:44:39+00:00

I have an unordered list. When the user clicks on an item it calls

  • 0

I have an unordered list. When the user clicks on an item it calls a function. I used the $(document).ready() event to bind the function to the list items.

The problem I have is that the contents of the list are replaced from time to time using the $('#list').html() method (using AJAX). This means that the binding on each item is lost.

I tried binding the function to the list (instead of the items). This works fine except that this is then a reference to the list, not the clicked item, and I am using this in my function.

The options I see are:

  1. After the contents of the list are reloaded, re-bind the function to each item. This seems to me like a lot of work for the browser to have to do.
  2. Bind the function to the list (not the list items), and work out how to reference the clicked list item from there.

Which would you use? How? Is there a better way?

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-18T12:44:40+00:00Added an answer on June 18, 2026 at 12:44 pm

    The second point you mentioned is called event delegation and would be a good solution here. Fortunately, jQuery makes event delegation very easy:

    $('#myList').on('click', 'li', function(){
        // `this` refers to the clicked `li` element
    });
    

    jQuery figures out the reference for you, i.e. inside the event handler this will refer to the li element that was clicked (the element that matches the second selector.

    Read more about direct and delegated event handling with jQuery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function when a user double clicks a horizontal list, that element
In a user control I have an unordered list that contains items showing editable
I'm going to have a unordered list ( <UL> ) of items. Each item
I have a unordered list <ul id=images > . There are 3 list items
I have an unordered list whose list items are displaying inline. However, its layout
I have an unordered list: <div class=toplist> <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li>
I have an unordered list <ul> with list items <li> which I'd like to
I have an unordered list, each list item has an id (id=6~OriginalName) - when
I have an unordered list with no list items. I get some information from
I work with an unordered list of links. When a user clicks on the

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.