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

  • Home
  • SEARCH
  • 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 7935555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:57:28+00:00 2026-06-03T21:57:28+00:00

I have a DOM structure below: <div class=’box’> <section id=profile> <h1>testuser</h1> <div id=following> <a

  • 0

I have a DOM structure below:

<div class='box'>
    <section id="profile">
        <h1>testuser</h1>
        <div id="following">
            <a class="btn unfollow" style="width: 180px;" rel="nofollow" data-remote="true" data-method="delete" href="/users/testuser/unfollow">Unfollow</a>
        </div>
    </section>
</div>

Then I have a trigger on the response to the link and I have a $(this). I can confirm that I am at this point in the DOM with some console logging.

Doing a $(this).parent() give me the div with the id #following.

However I can’t select the #profile or .box using parents(). Doing a parent().parent() also gives a nil?

Is there some reason I cannot traverse up the DOM tree over the section tag?

  • 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-03T21:57:31+00:00Added an answer on June 3, 2026 at 9:57 pm

    Try using $.closest():

    $(this).closest(".box");
    

    Of course this problem seems a bit suspicious. I was able to successfully access .box (and #profile) with $.parents without problem:

    $(".box").on("click", "a.btn.unfollow", function(e){
      e.preventDefault();
      $(this).parents(".box").css("background-color", "red");
    });
    

    http://jsbin.com/uranit/edit#javascript,html

    We’d need to see how you went about selecting these elements.

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

Sidebar

Related Questions

I have the following DOM structure: /*:DOC += <div id='testDiv' class='testDivClass'><div id='innerTestDiv'></div></div><span id='testSpan' class='testSpanClass'><span
I have the following DOM structure: <div class=city> <div class=a>Delete</div> <div class=b>Selected</div> <div class=c>Delete</div>
I have the following dom structure: <div class=ui-tabs> <ul> <li class=ui-state-default ui-tabs-selected ui-state-active> <a
I have a DOM structure that looks like this: <div class=chapter> <section></section> <section></section> </div>
I have the following DOM: <div class=qtip qtip-light qtip-active> <div class=qtip-wrapper> <div class=qtip-borderTop></div> <div
If I have the following DOM elements <div class=item>content1</div> <div class=item>content2</div> how, using jQuery
I have the following DOM structure: <div id=module-main> <div id=module-crumbs> <h4>Hello</h4> </div> </div> When
I have this structure in my dom: <label>London<input type=checkbox name=London></label><br> <div class=innerpost> <label>N1 2AB<input
I have the following structure: <form> <div class=content> ... </div> <div class=action> <p>Select <a
I have such dom structure: <div class=wrapper> <div class=style1> ... another divs ... </div>

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.