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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:30:50+00:00 2026-06-04T08:30:50+00:00

Example, if I have an unordered list lets say, <ul> <li class=foo>Foo</li> <li class=bar>Bar</li>

  • 0

Example, if I have an unordered list lets say,

<ul>
    <li class="foo">Foo</li>
    <li class="bar">Bar</li>
</ul>

I can select foo as $('ul li.foo'), $('li.foo') or $('.foo').

Then which way is more efficient (if any) and why. Or is it that specifying parents while selecting children is only for the sole reason to remove any conflict in case there are other elements having same class name!

  • 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-04T08:30:52+00:00Added an answer on June 4, 2026 at 8:30 am

    The simple class selector .foo will be fastest in modern browsers, because it can use the native getElementsByClassName where available.

    Here’s a benchmark showing exactly that:

    enter image description here

    You can run that performance test in all the browsers that matter to you, and make a decision based on the results. Or just use the selector that works best for your situation, since in the real world it’s going to make no noticeable difference whatsoever.

    Update

    Now that we can see the performance results from a wider selection of browsers, you can see the difference between old and new (lack of getElementsByClassName in IE7 and 8). However, you are likely these days to receive significantly more traffic from newer browsers, but I don’t know your site, so as I mentioned previously, you just need to pick what works for you. If for whatever reason 90% of your traffic comes from IE7, you should probably use li.foo.

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

Sidebar

Related Questions

I have a nested unordered list representing a tree hierarchy. There can be many
I have two or more unordered lists with the first list item in each
I have unordered list which has bulleted text within. I need to indent the
i have an unordered list of horizontal/vertical segments of length 1, which build one
I have three unordered list each surrounded by a container div (An example is
I have created an unordered list inside a div which is absolutely positioned. When
For example, I have a div with an id (lets say the_div). This div
Say, I have the following unordered list. The button has width: auto . How
I have an unordered list: <ul class=list_arrow2> <li> <span style=display: inline-block; width: 150px; font-weight:
Example: I have an class that inherits from UIImageView. An object creates an instance

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.