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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:35:08+00:00 2026-05-27T05:35:08+00:00

I am trying to use jQuery(#element-id).parent().addClass(‘some-class’); I have a structure something like this: <div

  • 0

I am trying to use

jQuery("#element-id").parent().addClass('some-class');

I have a structure something like this:

<div class="tab-container user-dash-tabs">
    <div class="tabs1">
        <ul class="shadetabs" id="countrytabs">
            <li class="poll"><a id="pillow-pack" rel="country2" href="javascript:;" class="selected"></a></li>
            <li class="bott"><a href="javascript:;" class="" id="bottles" rel="country1"></a></li>
        </ul>
        <div class="cl"></div>
    </div>
    <input type="hidden" class="input-search" value="123" id="lubepack" name="lubepack">
    <p></p>
    <div class="cl"></div>

    <div class="tabcontent tab-content" id="country1" style="display: none;">
        <ul class="left-tab">
            <li title="water based" class="  add"><a class="  tab-pic7" id="tab-pic7-b" title="water based" href="javascript:;">&nbsp;</a></li>
            <li title="silicone based"><a class="  tab-pic8" id="tab-pic8-b" title="silicon based" href="javascript:;">&nbsp;</a></li>
            <li title="arousal"><a class="  tab-pic9" id="tab-pic9-b" href="javascript:;">&nbsp;</a></li>
            <li title="flavored"><a class="  tab-pic10" id="tab-pic10-b" href="javascript:;">&nbsp;</a></li>
            <li title="organic"><a class="  tab-pic11" id="tab-pic11-b" href="javascript:;">&nbsp;</a></li>
            <li title="desensitizing"><a class="  tab-pic12" id="tab-pic12-b" href="javascript:;">&nbsp;</a></li>
            <div class="cl"></div>
        </ul>
        <div class="cl"></div>
    </div>
    <div class="tabcontent tab-content" id="country2" style="display: block;">
        <ul class="left-tab">
            <li class=" " title="water based"><a class="  tab-pic7" id="tab-pic7-p" title="water based" href="javascript:;">&nbsp;</a></li>
            <li title="silicone based"><a class="  tab-pic8" id="tab-pic8-p" title="silicon based" href="javascript:;">&nbsp;</a></li>
            <li title="arousal"><a class="  tab-pic9" id="tab-pic9-p" title="" href="javascript:;">&nbsp;</a></li>
            <li title="flavored"><a id="tab-pic10-p" class="  tab-pic10" href="javascript:;">&nbsp;</a></li>
            <li title="organic"><a id="tab-pic11-p" class="  tab-pic11" href="javascript:;">&nbsp;</a></li>
            <li title="desensitizing"><a id="tab-pic12-p" class="  tab-pic12" href="javascript:;">&nbsp;</a></li>
            <div class="cl"></div>
        </ul>
        <div class="cl"></div>
    </div>

    <script type="text/javascript">
        var countries=new ddtabcontent("countrytabs")
        countries.setpersist(true)
        countries.setselectedClassTarget("link") //"link" or "linkparent"
        countries.init()
    </script>

    <div class="cl"></div>
    <div class="search-box fl"><input type="text" id="name" class="input-search" name="name" value=""></div>
    <div class="cl"></div>
</div>

As you can see, one div is hidden while the other is visible.

Whenever a link is clicked, a class of add should be applied to it’s parent.

j("#" + id + "-p").parent().addClass("add");
j("#" + id + "-b").parent().addClass("add");

But, it’s only adding the class to the <li> that is hidden. If I execute the same code from the Firebug console. It works fine.

I tried creating a method for doing this, still the same result. I am not sure why I am facing this kid of problem. If anyone has faced similar problem, please let me know.

  • 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-05-27T05:35:09+00:00Added an answer on May 27, 2026 at 5:35 am

    The issue is because you are using parent() which only looks one level up the DOM tree from the current element, which in your case is the li. You need to use closest() instead, which will traverse it’s way up the entire DOM until it finds the first element matching the selector provided.

    With that in mind, the following should work for you:

    j("#" + id + "-p").closest("DIV").addClass("add");
    j("#" + id + "-b").closest("DIV").addClass("add");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to use jQuery to add a different class for each Span element,
I'm trying use jquery to remove a class from an element (not knowing ahead
I am trying to use JQuery in my ASP.Net 2.0 website in this scenario:
I'm trying to use jQuery UI tabs much like a Master Page in ASP.Net.
I am trying to use jQuery(document).ready(function () { if (!jQuery.browser.msie <= 7.99) { jQuery('#element').css('display',
I'm trying to use jQuery to insert HTML into a table element. I've been
I am trying to use JQuery to select the next element in a set
I'm trying to use 'errorPlacement' from jQuery Validation DOCS : $(#myform).validate({ errorPlacement: function(error, element)
I'm trying to use jquery.qtip to an anchor element in jquery.datatables. Basically how it
I'm trying to use jQuery's $(this) inside of Fancybox's onComplete event, but I'm running

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.