0
I made a toggle button using this code:
// Hide all the elements in the DOM that have a class of "box"
$('.box').hide();
// Make sure all the elements with a class of "clickme" are visible and bound
// with a click event to toggle the "box" state
$('.clickme').each(function() {
$(this).show(0).on('click', function(e) {
// This is only needed if your using an anchor to target the "box" elements
e.preventDefault();
// Find the next "box" element in the DOM
$(this).next('.box').slideToggle('fast');
});
});
body {
font: 12px/16px sans-serif;
margin: 10px;
padding: 0;
}
.clickme {
background-color: #eee;
border-radius: 4px;
color: #666;
display: block;
margin-bottom: 5px;
padding: 5px 10px;
text-decoration: none;
}
.clickme:hover {
text-decoration: underline;
}
.box {
background-color: #ccc;
border-radius: 4px;
color: #333;
margin: 5px 0;
padding: 5px 10px;
width: auto;
}
<a href="#" class="clickme">Click Me</a>
<div class="box">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<a href="#" class="clickme">Click Me</a>
<div class="box">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
But I have a very annoying problem when you click on more than one toggle button they end up accumulating and it gets really ugly normal img: img with the toggle Buttons in show.
Well I wish I just had to open one at a time or when one opens the other close is it possible to do this? Someone could give a light?
Bro I didn’t find any plugin to download you know tell what I call in the script p work? Or use only this code q vc sent?
– Felipe
You have to add Jquery
– Marcelo Batista
https://jquery.com
– Marcelo Batista
Add the bootstrap, download and add to the project along with jquery
– Marcelo Batista
I can add it to my already made code?
– Felipe
What I am was done by j query I’m just with this annoying little problem ;x
– Felipe
Yes download the jquery put in a folder and using the <script src="js/jquery.js" ></script> - example - add both jquery and bootstrap tag, it is worth you studying both mainly the bootstrap components and jquery, as both are widely used
– Marcelo Batista
I already have the 2 downloaded Pow and I created toggle by jquery just don’t know how to add to my jquery code this bootstrap plugin ..
– Felipe
I’m half lost kk
– Felipe
I used the code that Francis commented, but the toggle opens and closes very quickly I wanted him to open and stay just close when opening another .
– Felipe
Got it, in fact you should add the html structure with the bootstrap to have Collapse, and add the jquery I passed, the html code I put contains the bootstrap, you can use it as a reference to encode your html
– Marcelo Batista