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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:03:09+00:00 2026-06-03T12:03:09+00:00

I am using Jquery 1.7.2. I want to transverse Html Elements Till a Specifc

  • 0

I am using Jquery 1.7.2.

I want to transverse Html Elements Till a Specifc Attribute (id) using Jquery on
mouse over on any html element in my page.

we have parents() function but problem is how to select stop on the parent element which has id attribute

$("*", document.body).click(function (e) {
  e.stopPropagation();
  var domEl = $(this).get(0);      
      var parentEls = $(domEl).parents()
        .map(function () { 
              return this.tagName; 
            })
        .get().join(", ");

$(“b”).append(“” + parentEls + ““);
});

this is code but i am getting all element till root
but i want to stop on a closet elements which has attribute id in the tag

Please help me out .

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

    Just use closest:

    $(this).closest('#the-id');
    

    Unless your’e just looking for the closest one that has any id attribute, which would be:

    $(this).closest('[id]');
    

    Edit: after seeing your updated question, this should be what you want:

    $(document).click(function(e) {
        e.preventDefault();
        var parents = $(e.target).parentsUntil('[id]')
            .map(function() { return this.tagName; }).get().join(',');
        console.log(parents);
    });
    

    Note that this approach accomplishes what you want without selecting and binding click events to every node in the DOM, which is a pretty heavy handed approach.


    Edit (again): looks like maybe you wanted to include the tag with the id attribute on it (the above solution is everything up to, but not including that tag). To do this, the solution is pretty similar:

    $(document).click(function(e) {
        e.preventDefault();
        var $parents = $(e.target).parentsUntil('[id]');
        var tagNames = $parents.add($parents.parent())
            .map(function() { return this.tagName; }).get().join(',');
        console.log(tagNames);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input running in an HTML page. I'm using jQuery UI.I want
all I want to show hide some ids using jQuery. My html code is
I want to do a simple drag-drop using jQuery. I have not done anything
I have a <input type=hidden value= id='h_v' class='h_v'> Using jQuery I want to alert
Using jQuery I want to give a specific element the same width (or min-width
I'm using jQuery and I want to check the existence of an element in
Using jQuery I want to be able to click an element which will also
I have an ASP.NET webservice that returns JSON. Now, using jQuery I want to
Using jQuery I want to bind an existing function to a button. I've been
I want to read multiple RSS feeds using jQuery. I'm trying to write a

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.