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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:33:23+00:00 2026-05-26T16:33:23+00:00

On my website I have several hidden div’s with comments. Each comment div is

  • 0

On my website I have several hidden div’s with comments. Each comment div is for a

different article. Then I have a link which calls a jQuery UI function that expands hidden

div’s.

Here is an example http://jsfiddle.net/g7LwM/18/

The problem, as you can see, is that it expands all hidden div’s, where as I only need to

expand one which is related to a article. I can give an id of the article to each hidden

div e.g. .commentsBox 1 , .commentsBox 2 , .commentsBox 3 But I don’t know how to modify

jQuery function so it only expands a .commentsBox with a certain id. So this is my

question, How do I need to modify the code so when I click a .st_commentsa link of the article, it expands a hidden .comentsBox of that same article only?

Full code:

<head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    $(".st_commentsa").toggle(function() {
        $(".comentsBox").show("slide", {
            direction: "up"
        }, 200);
    }, function() {
        $(".fb-comments").hide("slide", {
            direction: "up"
        }, 200);
    })

})
</script>

</head>

<body>

<ul>
<li><a href="#" class="st_id">Click me</a></li>
<li><a href="#" class="st_time">Click me</a></li>
<li><a href="#" class="st_author">Click me</a></li>
<li><a href="#" class="st_verification">Click me</a></li>
</ul>
<div class="commentsBox 1" style="display: none;"><img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png"/>
</div>

<br /><br />

<ul>
<li><a href="#" class="st_id">Click me</a></li>
<li><a href="#" class="st_time">Click me</a></li>
<li><a href="#" class="st_author">Click me</a></li>
<li><a href="#" class="st_verification">Click me</a></li>
<li><a href="#" class="st_comments">Click me</a></li>
</ul>
<div class="commentsBox 2" style="display: none;"><img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png"/>
</div>

</body>
  • 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-26T16:33:24+00:00Added an answer on May 26, 2026 at 4:33 pm
    $(document).ready(function() {
        $(".st_comments").toggle(function() {
            $(this).closest('ul').next('div.commentsBox').show("slide", {
                direction: "up"
            }, 300);
        }, function() {
            $(this).closest('ul').next('div.commentsBox').hide("slide", {
                direction: "up"
            }, 300);
        })
    })
    

    I use the closest(‘ul’) has it helps jquery find the thing. the commentsBox div is next to the list element, not the ‘a href’ one (the one clicked). This method is cleaner, and offers better performance too.

    EDIT and for your second html:

    $(document).ready(function() {
        $('li > a').toggle(function() {
            $(this).closest('ul').next('div.commentsBox').show("slide", {
                direction: "up"
            }, 300);
        }, function() {
            $(this).closest('ul').next('div.commentsBox').hide("slide", {
                direction: "up"
            }, 300);
        })
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my website, I have several html files I do not link off the
We have redesigned the structure to a website which has several business units. Now
I have an company asp.net website with textboxes which may contain several hundred words.
I have several DropDownList in my website, and they are filtering each other. So,
I have a classifieds website, which uses PHP and MYSQL. I have several pages
I have several projects and a website in a large asp.net solution. In some
We have several wizard style form applications on our website where we capture information
I'm writing multilingual website. I have several files on server like: /index.php /files.php /funny.php
I have tried several ways to login to a website through java. I have
I have a website with several forms that all pass the same set of

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.