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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:21:45+00:00 2026-06-12T12:21:45+00:00

I have some HTML blocks look like <li id=item261> <div class=itemdesc> <a class=icon-hide>Hide</a> </div>

  • 0

I have some HTML blocks look like

<li id="item261">
    <div class="itemdesc">
      <a class="icon-hide">Hide</a>
    </div>
</li>

And i have a jquery like

$(document).ready(function()
{
$('.icon-hide').click(function(){
          var elemId = $(this).parent().attr("id");         
    });
});

I need the ID of the “li” tag on click of “.icon-hide”. how can i achive this? any help..

  • 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-12T12:21:47+00:00Added an answer on June 12, 2026 at 12:21 pm

    I’d suggest:

    $('.icon-hide').click(function(){
        var elemId = $(this).closest('li').attr('id');
    });
    

    This is because parent() as implied in the name of the method looks at the parent of the element returned by the selector (the parent is the div); whereas closest() continues up the ancestor tree to match the first selector passed to the method.

    You could, instead, use parents(), however the important difference between closest() and parents() is that closest() returns zero or one match, whereas parents() will continue all the way to the root element and return every match it finds, so it can return zero, one or many matches.

    Another difference is that parents() starts searching from the current element’s parent, whereas closest() starts with the current element itself, so it’s quite easily possible, using closest() for the method to return the current/$(this) element itself.

    References:

    • closest().
    • parent().
    • parents().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some html like the following: <div class=control-group> <input type=text data-bind=value: $data.DealCode name=DealCode
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=block> <div id=item1></div> <div id=item2></div>
I have some Html like: <div id=adiv> <ul> <li data-id=3>Cat</li> <li data-id=4>Dog</li> </ul> </div>
I have been given some html that look like this (I have no control
I have some html returned from an ajax call that contains blocks of html.
I am using Zend Dom component to parse some Html blocks, but i have
I have some HTML taken from an originally printed document. It has some page
Hi i have a repeating recordset, in which i want to hide some entry(html
I am having some problems to get my div box holders to look 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.