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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:52:21+00:00 2026-05-12T06:52:21+00:00

I know I’m just being OCD about a few milliseconds worth of performance time,

  • 0

I know I’m just being OCD about a few milliseconds worth of performance time, but I was just wondering why the following is true for me. It seems goes against my logic.

I currently have a div that has fades out the image inside on hover:

$('div.someclass').hover(function() {
    $(this).children('img').fadeOut(function(){
        // do something
    });
}, function() {
    // do something
});

After some testing, (looping through selectors 1000 times, taking the average of 9 tests) I have used 3 different selectors and concluded that the speed is in this order:

  1. $(this).children('img') runs the fastest -avg about 400ms;
  2. $('img', this) – avg about 900ms; and
  3. $(this).find('img') runs the slowest – avg about 1000ms

This goes against the logic that having two function calls would be slower than one. Plus, I have read that internally, jQuery converts the second case to the third case so would the third case be slower?.

Any thoughts?

  • 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-12T06:52:21+00:00Added an answer on May 12, 2026 at 6:52 am

    The difference between $(this).find('img') and $(this).children('img') is that the children function only looks for direct <img> descendants, while the find function finds any <img> element anywhere in the DOM hierarchy below $(this). That’s why children is faster.

    $(this).children('img'):

    <h1>                           <!-- Is this img? Nope! -->
        <img alt="" src="..." />   <!-- Never checked. -->
        <span>Bla bla</span>       <!-- Never checked. -->
    </h1>
    <a href="#">                   <!-- Is this img? Nope! -->
        <img alt="" src="..." />   <!-- Never checked. -->
    </a>
    <img alt="" src="..." />       <!-- Is this img? Yeah, return it! -->
    

    $(this).find('img'):

    <h1>                           <!-- Is this img? Nope! -->
        <img alt="" src="..." />   <!-- Is this img? Yeah, return it! -->
        <span>Bla bla</span>       <!-- Is this img? Nope! -->
    </h1>
    <a href="#">                   <!-- Is this img? Nope! -->
        <img alt="" src="..." />   <!-- Is this img? Yeah, return it! -->
    </a>
    <img alt="" src="..." />       <!-- Is this img? Yeah, return it! -->
    

    As you can see, there are three elements that won’t be checked when using children, thus increasing performance.

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

Sidebar

Related Questions

I know you can not set a key value dynamically, but what about the
I know little about sockets but so far I haven't had much of a
I know about this question , but I have the source and I'm having
know nothing about php, but I have this script that reads a folder and
I know that there has been one question about this but it is not
Know this might be rather basic, but I been trying to figure out how
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
i know this is a stupid question but i d'ont know how to do
I know questions like this have been asked before, but I'm not sure how

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.