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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:55:38+00:00 2026-06-17T21:55:38+00:00

I have TD elements with anchor tag inside them and divs which I want

  • 0

I have TD elements with anchor tag inside them and divs which I want to be revealed when the anchor tag is clicked. Also, I want others to close when any one of them is clicked, if it;s open already.

HTML:

<td>
<a href="#"><img src="images/1.jpg" /></a>
<div class="test"><p>test</p></div>
</td>

<td>
<a href="#"><img src="images/1.jpg" /></a>
<div class="test"><p>test</p></div>
</td>   

I tried with this JQuery but for some reason I have to click twice for it to show the div the first time, and if I then click on the second one the first one doesn’t close. I don’t need to add any classes.

<script type="text/javascript">
$(document).ready(function() {
    $('.test').hide();
    $('td a').on('click', function() {
        var state = $(this).next('.test').is('.open');
        if (state) {
            $(this).removeClass('active').next('.test').removeClass('open').show();
        }else{
            $(this).addClass('active').next('.test').addClass('open').hide()
                   .siblings('.test').removeClass('open').show().end()
                   .siblings('.test').not(this).removeClass('active');
        }
    });
});
</script>   
  • 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-17T21:55:39+00:00Added an answer on June 17, 2026 at 9:55 pm

    You can do it without saving state using toggleClass() to toggle the .active class and toggle() to show/hide the current test div.

    $('.test').hide();
    
    $('td a').on('click', function () {
      var $target = $(this).next('.test'); 
    
      $('.test').not($target).hide();
      $target.toggleClass('.active').toggle();
    });
    

    In addition I also use not() to hide all other test divs which are not the current one.


    DEMO – Toggle Divs


    I used the following HTML in the DEMO

    <table>
      <tbody>
        <tr>
          <td> <a href="#"><img src="http://placehold.it/100x50" /></a>
    
            <div class="test">
              <p>test</p>
            </div>
          </td>
          <td> <a href="#"><img src="http://placehold.it/100x50" /></a>
    
            <div class="test">
              <p>test</p>
            </div>
          </td>
        </tr>
      </tbody>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery code which runs on dom ready. It also creates elements
I have an anchor tag with text and I want to check if the
I have an anchor tag on my page, I want an event attached to
I have a grid and there is a column which contains <a> anchor tag
I have two elements (a button and an anchor tag) both with a dynamical
I have a Colorbox anchor tag which opens a box with external html. I
I have an image tag enclosed in an anchor element like this: <a href='$image'><img
I have elements structured roughly like this: http://jsfiddle.net/zyySd/ Is there any way to achieve
I want to parse xml files that have elements like these: <element>&amp</element> <element>&amp;</element> But
I currently have two anchor tags sending url queries to put votes inside 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.