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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:14:34+00:00 2026-06-08T01:14:34+00:00

Scenario I have a list of users, within each list item is a <header>

  • 0

Scenario

I have a list of users, within each list item is a <header> and a <div> wrapper – they are siblings:

<li class="user">
    <header>
        // ...
    </header>
    <div class="user-wrapper">
        // ...
    </div>
</li>

I am toggling the div wrapper when the user header is clicked.

What currently works:

// the handler is called
$('li.user > header').live('click', function () {
    $(this).next('.user-wrapper').toggle();
});

As live() has been deprecated and I am using jQuery 1.7.2, I want to use on().

What does not work:

// Direct style
$('li.user > header').on('click', function () {
    $(this).next('.user-wrapper').toggle();
});

// Delegated style
$('li.user').on('click', 'header', function () {
    $(this).next('.user-wrapper').toggle();
});

In either on() scenario, the anonymous handler function is not being called.

Question

First… why is on() choking?

Second… if/when it works, using the delegate style, can i still reference the header’s sibling div in the same manner as above?

  • 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-08T01:14:36+00:00Added an answer on June 8, 2026 at 1:14 am

    [EDITED]

    For delegate event handling the syntax of .on() is:

    // 'element' must be static and an ancestor to 'target'.
    $(element).on(eventName, target, handlerFunction);
    

    Your delegate scenario above should work, assuming your li.user tags are static at the time of binding.

    $('li.user').on('click', 'header', function () {
        $(this).next('.user-wrapper').toggle();
    });
    

    If you test this in jsFiddle, it works as is. It seems like your li.user elements are being created dynamically.

    If li.user is dynamically created then use a different (static) parent selector. If your list ul is always present, for example:

    // HTML
    <ul class="user-list">
      <li class="user">
        <header>
            // ...
        </header>
        <div class="user-wrapper">
            // ...
        </div>
      </li>
    </ul>
    
    // JavaScript
    $('ul.user-list').on('click', 'li.user > header', function() {
      $(this).next('.user-wrapper').toggle();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following scenario: I have RESTful URL /articles that returns list of articles user
I have a scenario where i a was taking a list of users (20
I have the following scenario: class Task { int id; Group group; User user;
I have class Group which contains list of users that are members of group.
I am using rails and have the following scenario: Users have_many lists and each
My Scenario: I have a list in groupView and childView of Expandable list. GroupView
Scenario I have a method that returns a list of processes using WMI. If
To simplify the scenario, let's say we have a list of People with FirstName
Scenario: I have an outline where I have links for my menu. Each link
This is the scenario i have: im developing a web app that will list

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.