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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:19:04+00:00 2026-06-14T04:19:04+00:00

I have HTML looks like: <div class=group_box> <div> <div> … <!– I don’t know

  • 0

I have HTML looks like:

<div class="group_box">
  <div>
     <div>
       ... <!-- I don't know haw many div's here -- >
       <a class="mark_as_read" ...>
     </div>
  </div>
<div>

....

<div class="group_box">
  <div>
     <div>
       ... <!-- I don't know haw many div's here -- >
       <a class="mark_as_read" ...>
     </div>
  </div>
<div>

I want to hide parent “group_box” when user click on “mark_as_read”.

Something like this:

<script type="text/javascript">
  $().ready(function() {
    $('.mark_as_read_link').bind('click', function() {
      alert($(self));
      $(self).parent('.group_box').hide();
      return false;
    });
 });
</script>

But it doesn’t work. I have not idea what is $(this) in this case….

  • 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-14T04:19:05+00:00Added an answer on June 14, 2026 at 4:19 am

    Instead of .parent() you can use the .closest() method, which will traverse up the DOM until it finds an element that match the selector.

    <script type="text/javascript">
      $().ready(function() {
        $('.mark_as_read_link').on('click', function() {
          $(this).closest('.group_box').hide();
          return false;
        });
     });
    </script>
    

    In the example I use .on() instead of .bind(). As of jQuery 1.7, .bind() has been deprecated in favor of .on() for attaching event listeners.

    Update:

    As Joonas points out in his comment, it would be possible to use the .parents() method, instead of .closest() as suggested above. The difference is that .parents() will keep traversing up the DOM, even if it encounter an element that matches the selector, while .closest() will stop traversing as soon as it finds a match. In this case I believe .closest() is more suited for the purpose, but if you consider using .parents() instead, here are the differences, stated in the documentation:

    .closest()

    • Begins with the current element
    • Travels up the DOM tree until it finds a match for the supplied selector
    • The returned jQuery object contains zero or one element for each element in the original set

    .parents()

    • Begins with the parent element
    • Travels up the DOM tree to the document’s root element, adding each ancestor element to a temporary collection; it then filters that collection based on a selector if one is supplied
    • The returned jQuery object contains zero or more elements for each element in the original set
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML that looks like this: <div class=product> Content In Here <div
So I have some html that looks like the following: <div class='something unknown' id='something_unknown_1'>
I have html that looks like this with several items <div class=item> <p class=price>$388.00</p>
I have some HTML that looks like this: <div> <div class=value> <a href=# class=clicker>Some
I have some HTML that looks like this: <div class=MyClass></div> <div class=MyClass></div> <div class=MyClass></div>
I have some html that looks like this: <div class=generated> <p><label for=id_group>Group</label> <select name=group
I have some HTML that looks like this: <h2>Heading</h2> <div class='myClass'> <h2>Another Heading</h2> </div>
I have html that looks something like this: <div> <table> <tr onclick=show();> <td class=cell>Click
If I have some HTML that looks like this: <div id=text> This is some
I have a div directly under the body. My HTML looks like this: <body>

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.