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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:00:24+00:00 2026-05-15T13:00:24+00:00

Just curious if there is an established best way to target child elements inside

  • 0

Just curious if there is an established “best way” to target child elements inside of a parent element.

For example, if I want to create a click event on the children of a parent element, which one should be preferred?

a) give the parent element and id and do:

$('ul#parent li').click(function() {});

b) or, instead, give each of the children a class name and target them directly:

$('li.child').click(function() {});

I’m asking because I’m trying to squeeze out every bit of performance I can get in a somewhat large application. Logic would dictate that targeting an id is faster than targeting a classname, but does the parent > child structure negate that advantage and justify targeting by classname instead?

Thanks for any insight.

  • 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-05-15T13:00:25+00:00Added an answer on May 15, 2026 at 1:00 pm

    This would be the fastest option:

    $('ul#parent li').click(function() {});
    

    Always descend from an ID selector if possible.

    However if you have a lot of <li> elements, it’s cheaper to use .delegate(), like this:

    $('#parent').delegate('li', 'click', function() { });
    

    With .delegate() you’re attaching one event handler instead of n (number of <li>) event handlers, one for each <li>. It works off listening for the click to bubble up to the <ul>, if startup time is killing you, this is a much better option. It’s a tradeoff of startup time binding lots of handlers vs. the bubble cost (which is a very, very, very small cost). If you have lots of elements, this is almost always a better overall option.

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

Sidebar

Related Questions

Just curious if there is a way to find the number of keys in
Just curious if there's a way in netbeans to give type hints for regular
I am just curious if there is an elegant way to solve following problem
I'm just curious if there's a way to disable things like shell_exec() using the
I was just curious if there was a way to issue the following command,
just curious if there is a way to trigger operation (or attach event to)
The below code works, I'm just curious if there is a dynamic way to
I was just curious if there was an easy way to display a right
Is there a tool to integrate Mercurial into Visual Studio? I am just curious.
Just because I'm curious--is there any C analog to the functionality of the STL

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.