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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:30:51+00:00 2026-06-12T07:30:51+00:00

i am noticing a bug in jquery find. if i call foo.find with a

  • 0

i am noticing a bug in jquery find.

if i call foo.find with a selector that might reference foo itself, it won’t work. example here.

http://jsfiddle.net/CgfPj/6/ (EDIT: UPDATED THE fiddle to more clearly explain what i’m trying to do)

test.find should be able to find a span that is a child of a div, but it can’t seem to since the div is test itself. is this a bug?

  • 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-12T07:30:53+00:00Added an answer on June 12, 2026 at 7:30 am

    #test is the div you’re referencing.

    .find() returns the descendants of #test matching your given selector. #test has no descendant divs, hence test.find("div > span") doesn’t match any elements.

    To get the direct span descendants of #test you should use:

    test.find("> span")
    

    Fiddle


    Edit as per OP edit:

    $("#test > span, #test div > span")
    

    Will get all spans direct descendant of #test as well as all span elements direct descendant of divs inside of #test – fiddle.

    There’s no such thing as a :parentIs(div) selector in the CSS selectors spec nor in jQuery as far as I’m aware of, but you can easily fill that gap by using a filter function:

    var spans = test.find('span').filter(function() {
        return $(this).parent()[0].tagName.toLowerCase() === 'div';
    });
    
    $("#result").text(spans.length);
    

    Fiddle

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

Sidebar

Related Questions

Noticing how badly implemented is reference counting in current Objective-C (see here and here
I'm noticing that a:visited styles don't work on links that are requested via JavaScript.
I'm noticing that when I do a query such as the following: https://rally1.rallydev.com/analytics/1.27/41529001/artifact/snapshot/query.js?find={ _Type:
I'm noticing a problem that has crept up a few times over the years,
After reading several questions regarding problems with compilation (particularly C++) and noticing that in
I'm collecting text through a web form and noticing that when it is collected
I'm noticing some behavior that I don't like, and I'm wondering if this is
I'm noticing that MongoDB is collapsing multiple spaces together (into one space) when saving
I'm noticing that in places where our site uses special characters on a webpage,
I've been noticing superfluous changes in my xib files with Interface Builder 3.2.1. Here

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.