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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:24:55+00:00 2026-05-29T06:24:55+00:00

Does jQuery 1.5.1 support attribute selectors in the closest method? Given the structure below,

  • 0

Does jQuery 1.5.1 support attribute selectors in the closest method?

Given the structure below, el represents the checkbox with the value 513, and I’m trying to reach up and check the ancestor checkbox with the value of 0 with

$(el).closest("input[value='0']")[0].checked = true;

but the selector is returning nothing.

Am I missing something silly?

enter image description here


EDIT

Sigh, so the checkbox with value 0 isn’t an ancestor to el, just a sibling of the ul ancestor. I got it to work with

$(el).closest("ul").siblings("input[value='0']")[0].checked = true;

But us there a cleaner way to grab it?

  • 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-29T06:24:55+00:00Added an answer on May 29, 2026 at 6:24 am

    The .closest() method does support attribute selectors the same as any other jQuery method (although I don’t know about the specific version of jQuery you mentioned), but the problem here is that .closest() doesn’t just look in the general vicinity, it goes up through the ancestors. You are trying to select an input element that is not an ancestor of the element you are starting with. (Given that inputs can’t contain other elements they will never be the ancestors of anything…)

    You should be able to do it by selecting the target checkbox’s parent li element first:

    $(el).closest('li:has(input[value="0"])')
         .find('input[value="0"]').prop("checked",true);
    

    Demo: http://jsfiddle.net/Vpzyj/

    Of course if you were able to add a class to the top level menu items you wouldn’t need to mess around with “:has”, you could just say:

    $(el).closest('li.topMenu').find('input[value="0"]').prop("checked",true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does JQuery support Dictionaries (key, value) collection ? I would like to set the
Does the jQuery $.ajaxSetup method not respect the data field in the options hash
Does jQuery support XSL transformations of XML? If so how do I use it?
does jquery support multiples of $(document).ready(function() {}); ie. can i make a few of
Since my cell phone apparently doesn't support JQuery , but does run the simple
if one of the main benefits of jquery is cross browser javascript support, does
Does the iPhone has AJAX and jQuery support? I am developing a chatbox for
Does anyone maintain a list of jQuery plugins that support the jQuery UI CSS
Does jquery support both function pageload() and $().ready() ? Or is pageload() for ajax.net
Does jQuery have built in JSON support or must I use a plugin like

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.