javascript - twitter-bootstrap js to toggle all collapse for all elements of a common class -
i have bunch of elements (code-blocks) i'd able collapse using twitter-bootstrap's javascript, such as
some text <div class="highlight"> code code </div> more text text <div class="highlight"> code code </div> i can add following javascript make of these elements collapse:
$('highlight').collapse({ toggle: true }) now i'd add button toggle collapse/show these elements. ideas?
solution requirements
i'm looking solution
- extends doesn't have change original html code blocks. instance, cannot add ids 'highlight' divs or more divs around code blocks.
- in similar goal, i'd apply highlight class divs.
note using normal collapse class twitter bootstrap, such as:
<a href="#block1" data-toggle="collapse">toggle</a> <div class="collapse" id="#block1"> code code </div> doesn't gneralize in way, since needs ids, , if repeated, toggles first one
twitter bootstrap uses jquery behind scenes should able add button, add click event collapse code blocks.
<input type="button" value="show/hide" id="toggle_code" /> $(function(){ $('#toggle_code').click(function(){ $('.highlight').collapse({ toggle: true }) }); });
Comments
Post a Comment