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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:52:36+00:00 2026-05-25T23:52:36+00:00

I am using this jQuery function to find the parent element with class name

  • 0

I am using this jQuery function to find the parent element with class name “viewCommentsExp”.

 $('.viewCommentsExpBtn').click(function(e){
    e.preventDefault();

var trackid= $(this).parent().find(".trackidField2").val();
var parent = $(this).parent().parent().parent().find(".viewCommentsExp");

        $.ajax({
            type: "POST",
            data: "trackid="+trackid,
            url: "http://rt.ja.com/viewcomments.php",
            success: function(data)
            {   
             $(".newUserComment").html(data);
            $(parent).slideToggle();

                }
            });
     });

I have this function working on about 90% of the clicks. But, randomly, sometimes all divs with this classname are selected rather than the closest.

Can I clean this up to work more reliably using jQuery “closest”?

$(this).parent().parent().parent().find(".viewCommentsExp");

Not sure how to implement this.

  • 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-25T23:52:37+00:00Added an answer on May 25, 2026 at 11:52 pm

    If the elements being clicked will have a parent with some characteristic you can use (e.g., a class name or other attribute), then closest might be helpful. It depends on your HTML structure, which you haven’t shown (as of this writing, I’m guessing you’ll probably add it, but I have to disappear).

    For instance, if the elements will be in something with the class “container”, and the “viewCommentsExp” is a descendant of that “container” element, then:

    var viewCommentsExp = $(this).closest(".container").find(".viewCommentsExp");
    

    That would work, for instance, if you were looking for clicks on the button in this structure:

    <div class="container">
    <input type="button">
    <span class="viewCommentsExp">...</span>
    </div>
    

    …or any other structure where both the button and the “viewCommentsExp” were descendants of “container” (whether siblings or not).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jquery function which changes the class of element $(a).click(function(){ $(this).closest(ul).find(a).parent().removeClass(active); $(this).parent().addClass(active);
Using this jquery code: <a href=javascript:void(0) id=m1>Get Selected id's</a> jQuery(#m1).click( function() { var s;
I'm using this: jQuery('.class1 a').click( function() { if ($(.class2).is(:hidden)) { $(.class2).slideDown(slow); } else {
I'm using this jQuery to hide a DIV: $(#slider).click(function() { $(.help).slideToggle(); $(#wrapper).animate({ opacity: 1.0
I am using the jQuery $.ajax() function. I have put this into a parent
I have make a script by using jQuery such as : $(document).ready(function() { $('a[name=pmRead]').click(function(e)
ok i have this jquery $('.make_request').ajaxForm(function() { // $('.band_notice').show(); $(this).parents('.accordionContent').find('.band_notice').show(); }); I am using
I am using this jquery function that works fine in win/mac FF 3.5 and
I'm using this Jquery function for available username check. How can I fire this
$.each(3,function(i){ alert(i) }) alert 0,1,2 how to do this using jquery? thanks

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.