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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:07:25+00:00 2026-06-07T05:07:25+00:00

What is the difference between following different ways of jQuery selections. To me they

  • 0

What is the difference between following different ways of jQuery selections. To me they seem to be different ways of doing same thing with same performance costs:

$("#list li").hover(function () {
                $(this).addClass("red");
}, function (){
        $(this).removeClass("red");
});

With a greater than symbol:

$("#list > li").hover(function () {
                $(this).addClass("red");
}, function (){
        $(this).removeClass("red");
});

Add now with context:

$("li", $("#list")).hover(function () {
                $(this).addClass("red");
}, function (){
        $(this).removeClass("red");
});
  • 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-07T05:07:28+00:00Added an answer on June 7, 2026 at 5:07 am
    • #list li finds the same set of elements, but in a modern browser it can pass the whole selector to the browser’s selector engine so it might be much faster.

    • #list > li finds all li elements that are immediate children of #list, i.e. <ul id="list"><li> but not <div id="list"><ul><li>.

    • $("li", $("#list")) creates a jQuery object containing the element matching #list and then creates a new element containing any li elements with the context #list, i.e. all li elements that are inside #list. It is not really readable so don’t use that.


    There are also other ways:

    • $('#list').children('li') equals $('#list > li')
    • $('#list').find('li') equals $('#list li')

    Both cases cannot use the speed advantages of a native querySelectorAll so besides being more readable they are about as bad as $("li", $("#list"))

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

Sidebar

Related Questions

What's the difference between the following ways of attaching an event handler in JQuery?
Is there any difference between following two ways of creating an object. Student s1
Will there be a difference between the following two ways of calling a function
What's the difference between following relative paths? <script type=text/javascript src=../Scripts/jquery-1.2.6.js></script> <script type=text/javascript src=../../Scripts/jquery-1.2.6.js></script> <script
Is there a difference between the following two : ArrayList list = getData(); public
What is the main difference between these following two ways to give a method
In VB.Net is there any difference between the following three ways of initialising object
What is the difference between the following coding ways: if (String::IsNullOrEmpty(TextBox1->Text)) and if (TextBox1->Text
Is there a performance difference between the following two pieces of code? if (myCondition)
Are there any difference between following ways to init self? First: - (id)init {

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.