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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:08:16+00:00 2026-06-11T16:08:16+00:00

I have a problem with .closets() in jQuery On jQuery documentation tell that I

  • 0

I have a problem with .closets() in jQuery

On jQuery documentation tell that I can use like it.

<!DOCTYPE html>
<html>
<head>
  <style></style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <ul><li></li><li></li></ul>
<script>
  var close = $("li:first").closest(["ul","body"]);
  alert(close.length);
  </script>
</body>
</html>

http://api.jquery.com/closest/#closest2

In this part I get information about ul and body, two steps up of li

var close = $("li:first").closest(["ul","body"]);

But it doesn’t work, inside the close don’t have anything, it’s empty, what I’m doing wrong?
The code from jQuery documentation is wrong too. The example doesn’t work.

  • 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-11T16:08:18+00:00Added an answer on June 11, 2026 at 4:08 pm

    If you are trying to select the closest ul and the closest body, you should instead use .parents() and :first since the method you are currently trying to use has been removed in recent versions of jQuery.

    http://jsfiddle.net/MYjRm/

    var close = $("li:first").parents("ul:first,body:first");
      $.each(close, function(i){
      $("li").eq(i).html( this.nodeName );
    });​
    

    .closest() by definition can only select 1 element, since you’re looking for two, you should use .parents() which can select more than 1.

    If you simply want to select 1 element, use .closest() with a selector that will select that one element. $("li:first").closest("ul");

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

Sidebar

Related Questions

I have a problem in Jquery that whenever I click on checkbox and click
I have an HTML link that opens a jQuery modal dialog which contains an
i have a client side jquery script that logs the user off after 5
I have a jQuery script that works perfectly fine in Chrome 11 and Firefox
I have problem while loading data into html select when users press or click
I have a form that pops up using jQuery, when I click on submit,
I'm having a problem with this jQuery function, the portion of the function that
This is quite a talked about problem on the jQuery forums but I can't
I have created the widget in Jquery mobile for Tabs. I want that when
Got a small problem with some very basic jQuery, I'd like to be able

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.