Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery toggle doesnt work

Tags:

jquery

toggle

I need it so when you click on the other toggle, the box currently open closes, so its basically impossible for them to be both open at the same time?

But the toggle doesnt work. https://jsfiddle.net/3gorcdra/1/

My JS Code look like this:

    $('.mix').next('.mix-content').hide();
$('.mix').click(function() {
    var el = $(this).next('.mix-content');
    var doit = (el.is(':visible')) ? el.slideUp() : ($('.mix-content').slideUp()) (el.slideDown());
});

I hope you guys can help me.

like image 853
fr3d Avatar asked May 18 '26 04:05

fr3d


1 Answers

Try to use find() not next() since you are searching for descendant,

$('.mix').find('.mix-content').hide();
$('.mix').click(function() {
  var el = $(this).find('.mix-content');
  var doit = (el.is(':visible')) ? el.slideUp() : ($('.mix-content').slideUp(),el.slideDown());
});

DEMO

Also your css for mix-content is having position absolute. I changed it, because the accordion like behavior cannot be achieved like that.

like image 166
Rajaprabhu Aravindasamy Avatar answered May 21 '26 21:05

Rajaprabhu Aravindasamy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!