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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:37:50+00:00 2026-06-08T04:37:50+00:00

First: .closest(‘.notice’) It will take .notice itself or it will take whats nearest the

  • 0

First:

  .closest('.notice')

It will take .notice itself or it will take whats nearest the .notice up the dom tree?

.next('.notice') – it will grab whats down the dom tree, right?

Another one:

$('#celebTree ul').hide().before('<div class="bla"></div>').prev().addClass('handle closed')

with the .prev jQuery should select an element before “bla” and apply the class. But it is applying the class to the element that I am inserting with .before method. Why it is like 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-06-08T04:37:52+00:00Added an answer on June 8, 2026 at 4:37 am

    .closest('notice') is the closest parent that matches or the element itself if it matches:

    <div class="notice"> //This will be selected with $("#target").closest(".notice")
        <div id="target"></div>
    </div>
    
    <div class="notice">
        <div id="target" class="notice"></div>  //This will be selected with $("#target").closest(".notice")
    </div>
    

    .next('notice') selects the next element sibling if it matches:

    <div id="target"></div>
    <div class="notice"></div> //This will be selected with $("#target").next(".notice")
    
    <div id="target"></div>  //NOTHING will be selected with $("#target").next(".notice")
    <div></div>
    

    .before() doesn’t return a new jQuery object, it returns the old one that you inserted content before to:

    $('#celebTree ul').hide().before('<div class="bla"></div>') 
    //Returns the '#celebTree ul'. NOT jQuery object wrapping '<div class="bla"></div>'
    

    Since you just inserted before the element and prev operates on '#celebTree ul' here, prev will take the previous element sibling, which is that content.

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

Sidebar

Related Questions

first take a look on this picture from localScope app : i have 2
We can use closest(selector) to find the first ancestor element that matches the selector.
For example, i associate following function with some element $('table#users tbody tr:first #save').click(function(){ $(this).closest('tr').remove();
First time posting, I will try to adhere to best practices. I'm trying to
I'm trying to grab the first parent element that matches a class check, but
This is my first question. I gave up and will use a hand rolled
Hey guys here is my code: <script>$('td#view-details').click(function() { var fg = $(this).closest('td').siblings(':first-child').text(); $('#'+fg+'confirm').click(function ()
this is a snippet from my code: $("#myid").append($("p:contains('text')").closest("div").clone()); I tried to get the first
I am trying to get the first image <img> closest to the first <p>
i am loading some fragments with jquery with following code var box = $(this).closest(.product-contain).children(.title:first);

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.