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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:40:05+00:00 2026-05-15T15:40:05+00:00

i have a section in my website that needs to be toggled by clicking

  • 0

i have a section in my website that needs to be toggled by clicking on the title .

now i wrote this code to toggle when clicking on title

$(document).ready(function(){
$(".toggle_container").hide();
$("h4.trigger").click(function(){
  $(this).toggleClass("active").next().slideToggle("slow");
});
});

html part :

<h4 class="trigger"><a href="javascript:void(0)">'.$row[title].'</a></h4>
<div class="toggle_container">
 <div class="block">
  '.$row[text].'
 </div>
</div>

now with these codes everything goes fine , untill it just opens every title clicked and not closes opened ones ;

1st

now i have to change this script in a way that when i click on a title to toggle first check opened ones and close those first

2nd

and the other thing im wondering is how to make the first title to be opened already ,
when the page loaded the first title to be opened

thanks in advance

  • 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-15T15:40:06+00:00Added an answer on May 15, 2026 at 3:40 pm

    I was hoping one of the other answers would update and fix this, but both of them never toggle, they always show, here’s how to toggle and hide the others like you want:

    $(function(){
      $(".toggle_container:gt(0)").hide();
      $("h4.trigger").click(function(){
        $(this).toggleClass("active").next().slideToggle("slow")
               .siblings(".toggle_container").slideUp();
      });
    });
    

    You can try out a demo here, it shows the first on load, and correctly toggles the rest.

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

Sidebar

Related Questions

I have a section on my website that when a user clicks I would
I have a section of a website that has three divs next to each
I have a menu section on a website that consists of 2 rows with
I have a simple question and answer section on my website that allows comments.
I want to have a very simple editor for my website that i wrote
I have a separate section (route) of my website that I would like to
I have a website that needs to store two sets of user data into
I have a website that occasionally needs to have a handful of the tables
On the Freebase website topic pages they have a section called Related Topics. So
I have a website which slides to a section called blog in my HTML.

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.