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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:06:55+00:00 2026-05-17T17:06:55+00:00

When used with the child selector > , the two variants of jQuery’s has

  • 0

When used with the child selector >, the two variants of jQuery’s “has” behave differently.

Take this HTML:

<div>
  <span>Text</span>
</div>

Now:

$("div:has(>span)");

would return it, while:

$("div").has(">span");

would not. Is it a bug or a feature? Compare here: http://jsfiddle.net/aC9dP/


EDIT: This may be a bug or at least undocumented inconsistent behavior.

Anyway, I think it would be beneficial to have the child selector consistently work as an unary operator. It enables you to do something that otherwise would require a custom filter function — it lets you directly select elements that have certain children:

$("ul:has(>li.active)").show();     // works
$("ul").has(">li.active)").show();  // doesn't work, but IMHO it should

as opposed to:

$("ul").filter(function () {
  return $(this).children("li.active").length > 0;
}).show();

I’ve opened a jQuery ticket (7205) for this.

  • 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-17T17:06:55+00:00Added an answer on May 17, 2026 at 5:06 pm

    This happens because the sizzle selector is looking at all Div’s that have span children in the :has example. But in the .has example, it’s passing all DIV’s to the .has(), which then looks for something that shouldn’t be a stand-alone selection. (“Has children of nothing”).

    Basically, :has() is part of the selection, but .has() gets passed those divs and then re-selects from them.

    Ideally, you don’t use selectors like this. The > being in the selector is probably a bug, as it’s semantically awkward. Note: the child operator isn’t meant to be stand-alone.

    Sizzle vs target.sizzle:

    I’m always talking about v1.4.2 of jquery development release.

    .has (line 3748 of jQuery)

    Description: Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.

    Code:

        var targets = jQuery( target );
        return this.filter(function() {
            for ( var i = 0, l = targets.length; i < l; i++ ) {
                if ( jQuery.contains( this, targets[i] ) ) { //Calls line 3642
                    return true;
                }
            }
        });
    

    Line 3642 relates to a 2008 plugin compareDocumentPosition, but the important bit here is that we’re now basically just running two jquery queries here, where the first one selects $("DIV") and the next one selects $(">span") (which returns null), then we check for children.

    :has (line 3129 of jQuery)

    Description: Selects elements which contain at least one element that matches the specified selector.

    Code:

    return !!Sizzle( match[3], elem ).length;

    They are two differnt tools, the :has uses sizzle 100%, and .has uses targets passed to it.

    Note: if you think this is a bug, go fill out the bug ticket.

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

Sidebar

Related Questions

The .first() method was added in jQuery 1.4. The :first selector has been around
Never used a cache like this before. The problem is that I want to
I used jQuery to set hover callbacks for elements on my page. I'm now
When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between
I used to be able to do the following in Preview 3 <%=Html.BuildUrlFromExpression<AController>(c =>
I used the method $(#dvTheatres a).hover(function (){ $(this).css(text-decoration, underline); },function(){ $(this).css(text-decoration, none); } );
I'm trying to find a jQuery selector that will match only the element that
I was creating a tree using UL LI list and jQuery. I used a
I'm not sure this is possible, but is there a syntax to be used
Code Used: m_pButton->Create(LABC, WS_CHILD | WS_VISIBLE| BM_SETIMAGE,CRect(0,0,100,100),this,ID_BUTTON1); m_pButton->SetIcon(::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1))); //above Code show neither showing

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.