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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:32:37+00:00 2026-06-05T03:32:37+00:00

I have a bunch of elements (code-blocks) I’d like to be able to collapse

  • 0

I have a bunch of elements (code-blocks) I’d like to be able to collapse using twitter-bootstrap’s javascript, such as

some text

<div class="highlight">
code code
</div>

some more text text 

<div class="highlight">
code code
</div>

I can add the following javascript to make all of these elements collapse:

$('highlight').collapse({
  toggle: true
})

Now I’d like to add a button to toggle the collapse/show for these elements. Any ideas?

Solution requirements

I’m looking for a solution that

  1. extends but doesn’t have to change the original html with the code blocks. For instance, I cannot add ids to the ‘highlight’ divs or more divs around the code blocks.
  2. In a similar goal, I’d like it to apply to all highlight class divs.

Note that using the normal collapse class from twitter bootstrap, such as:

<a href="#block1" data-toggle="collapse">toggle</a>
<div class="collapse" id="#block1">
code code
</div>

doesn’t gneralize in this way, since it needs ids, and if they are repeated, it only toggles the first one

  • 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-05T03:32:39+00:00Added an answer on June 5, 2026 at 3:32 am

    twitter bootstrap uses jQuery behind the scenes so you should just be able to add a button, then add a click event to collapse the code blocks.

    <input type="button" value="show/hide" id="toggle_code" />
    $(function(){
        $('#toggle_code').click(function(){
            $('.highlight').collapse({
              toggle: true
            })
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that loads a bunch of images into hidden img elements and
I have a bunch of inline-block elements over several lines which I'd like to
I have a bunch of elements like the following: <div class=droppableP id=s-NSW style=width:78px; height:63px;
I'm using the following code to set a bunch of DataGridViewRow elements to be
I've successfully been able to make elements (like div's, panel's, whatever) draggable by using
I have a bunch of elements with ids like check1, check2, check3 etc. I
I have a bunch of elements with <div id='id1'></div> and would like to return
We have some existing JavaScript for enabling/disabling a bunch of checkboxes. After upgrading from
I have some code that puts a bunch of TNotifyEvents in a vector .
I have a bunch of span elements in random positions enclosed inside a parent

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.