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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:20:14+00:00 2026-06-09T04:20:14+00:00

I am trying to get clicked links’, all parent item classes using jQuery Ex

  • 0
I am trying to get clicked links', all parent item classes using jQuery

enter image description here

Ex –
when i click on “Painting of buildings facades with acrylic paint” i want get the classes

item150

item149

item143

i currently writes a j Query for this, but it give one closest li class, but cant get others it says undefined.

jQuery(".menu-sol a").click(function(event) {
event.preventDefault();
clicked=jQuery(this).closest('.parent').attr('class');
clicked=clicked.replace('parent ','');
clicked2=jQuery('.'+clicked).prev('.parent').attr('class');

alert(clicked);
alert(clicked2);

});

here is a part of html

  <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: auto;" id="level_3">
      <li class="parent item144"><span src="" title=""></span><span class="separator"><span>Repairs of plasters</span></span>
        <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: 0px;" id="level_3_0">
          <li class="item152"><a href="/Repairing-of-fallen-plaster.html"><span>Repairing of fallen plaster</span></a></li>
          <li class="item153"><a href="/Repairing-of-hairline-cracks-in-plaster.html"><span>Repairing of hairline cracks in plaster</span></a></li>
        </ul>
      </li>
      <li class="parent item145"><span src="" title=""></span><span class="separator"><span>Repairs of masonries</span></span>
        <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: 0px;" id="level_3_1">
          <li class="item154"><a href="/Repairing-of-masonry-cracks-crack-width.html"><span>Repairing of masonry cracks (crack width </span></a></li>
          <li class="item155"><a href="/Repairing-of-detached-masonry-from-the-supporting-elements.html"><span>Repairing of detached masonry from the supporting elements</span></a></li>
          <li class="item156"><a href="/Repairing-of-severe-masonry-cracks-cracks-width-1-cm-Disorganised-masonry.html"><span>Repairing of severe masonry cracks (cracks width &gt; 1 cm) - Disorganised masonry</span></a></li>
        </ul>
      </li>
      <li class="parent item146"><span src="" title=""></span><span class="separator"><span>Repairs of concrete elements</span></span>
        <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: 0px;" id="level_3_2">
          <li class="parent item147"><span></span><span class="separator"><span>Reinforcement with composite materials (F.R.P.)</span></span>
            <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: 0px;" id="level_3_2_0">
              <li class="item162"><a href="/Reinforcement-of-the-shear-strength-of-a-beam.html"><span>Reinforcement of the shear strength of a beam</span></a></li>
              <li class="item163"><a href="/Reinforcement-of-the-flexural-strength-of-a-beam-or-slab.html"><span>Reinforcement of the flexural strength of a beam or slab</span></a></li>
              <li class="item164"><a href="/Columns-confinement.html"><span>Column's confinement</span></a></li>
            </ul>
          </li>
          <li class="item157"><a href="/Repairing-of-peeled-concrete-due-to-corrosion-of-the-steel-reinforcement.html"><span>Repairing of peeled concrete due to corrosion of the steel reinforcement</span></a></li>
          <li class="item158"><a href="/Repairing-of-damaged-concrete-surface-damage-blisters-broken-corners-etc.html"><span>Repairing of damaged concrete (surface damage, blisters, broken corners etc.)</span></a></li>
          <li class="item159"><a href="/Repairing-of-damaged-concrete-elements-by-grouting-with-concrete-or-high-strength-mortar.html"><span>Repairing of damaged concrete elements by grouting with concrete or high strength mortar</span></a></li>
          <li class="item160"><a href="/Repairing-of-cracks-in-concrete-elements-with-resin-injection.html"><span>Repairing of cracks in concrete elements with resin-injection</span></a></li>
          <li class="item161"><a href="/Repairs-with-composite-materials-welding-metal-plates-to-concrete-elements.html"><span>Repairs with composite materials - welding metal plates to concrete elements</span></a></li>
        </ul>
      </li>
      <li class="parent item148"><span src="" title=""></span><span class="separator"><span>Painting</span></span>
        <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: auto;" id="level_3_3">
          <li class="parent item149"><span src="" title=""></span><span class="separator"><span>Acrylic paints</span></span>
            <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: auto;" id="level_3_3_0">
              <li class="parent item150"><span src="" title=""></span><span class="separator"><span>Painting of exterior surfaces</span></span>
                <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: 60px;" id="level_3_3_0_0">
                  <li class="item166"><a href="/Painting-of-buildings-facades-with-acrylic-paint.html"><span>Painting of buildings facades with acrylic paint</span></a></li>
                  <li class="item167"><a href="/Painting-of-building-facades-with-highly-elastic-waterproofing-paint.html"><span>Painting of building facades with highly-elastic waterproofing paint</span></a></li>
                </ul>
              </li>
              <li class="item165"><a href="/Painting-of-interior-surfaces.html"><span>Painting of interior surfaces</span></a></li>
            </ul>
          </li>
          <li class="parent item151"><span src="" title=""></span><span class="separator"><span>Epoxy paints</span></span>
            <ul style="padding-top: 0px; border-top: medium none; padding-bottom: 0px; border-bottom: medium none; overflow: hidden; height: 0px;" id="level_3_3_1">
              <li class="item168"><a href="/Painting-of-metal-surfaces-with-anti-corrosive-epoxy-primer.html"><span>Painting of metal surfaces with anti-corrosive epoxy primer</span></a></li>
              <li class="item169"><a href="/Painting-of-walls-with-high-durability-epoxy-coating.html"><span>Painting of walls with high durability epoxy coating</span></a></li>
              <li class="item170"><a href="/Waterproofing-of-pools-and-painting-with-epoxy-coating.html"><span>Waterproofing of pools and painting with epoxy coating</span></a></li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>

and you can access the example site via
http://isomat.eu/technical-solutions/menu-id-73

my goad is store clicked links parent item classes to cookie and load the same node when refreshing the page. can any one help me for getting the parent classes

thank you

  • 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-09T04:20:15+00:00Added an answer on June 9, 2026 at 4:20 am

    This will give you all parent nodes of the class parent:

    $(this).parents('.parent')
    

    Is that what you’re asking for?

    The following would give you a list of all class names, per parent:

    $(this).parents('.parent').map(function() {
        return $(this).attr('class').split(/\s+/);
    }).toArray();
    
    // [ [ "parent", "item150" ], [ "parent", "item149" ], ... ]
    

    Now, if you know that there will always be two classes, and that you’ll always want the second, you could do the following:

    $(this).parents('.parent').map(function() {
        return $(this).attr('class').split(/\s+/)[1];
    }).toArray();
    
    // [ "item150", "item149" ]
    

    Otherwise, if you can assume that there will only be one item... class, perhaps this would be a neater approach:

    $(this).parents('.parent').map(function() {
        var classes = $(this).attr('class').split(/\s+/);
        for(var i = 0; i < classes.length; i++) {
           if(classes[i].substring(0, 4) == 'item')
              return classes[i];
        }
    }).toArray();
    
    // [ "item150", "item149" ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I am trying to get the html value of a linked clicked. The links
I have unordered list of links and i am trying to get the clicked
I'm trying to use jQuery to find all links on a page, then when
HI, I'm trying to get accordion like functionality without using jQuery's UI accordion feature.
I am trying to get it so that when a link is clicked in
I am trying to get it so that when a specific <li> is clicked,
I'm trying to get the value of a <select> when a button is clicked.
I am trying get Struts 2 and Tiles to work and I am using

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.