Hey guys I have this jQuery content toggle setup here: http://jsfiddle.net/DTcHh/848/
I am trying to remove the class for the span that contains the plus glyphicon and replace it with the minus glyphicon when the content is visible.
Here is my jQuery:
$(document).ready(function () {
$('#toggle-view li').click(function () {
var text = $(this).children('div.panel');
if (text.is(':hidden')) {
text.slideDown('200');
$(this).children('span').html('-');
} else {
text.slideUp('200');
$(this).children('span').html('+');
}
});
});
Here is my HTML:
<ul id="toggle-view">
<li class="li-toggle">
<h3 class="toggle-h3">Title 1<span class="glyphicon glyphicon-plus glyph-plus-toggle"></span></h3>
<div class="panel">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim.</p>
</div>
</li>
</ul>
I have tried implementing this code to try and remove the plus glyph and replace it with the minus glyph however I can't get it to work:
$(this).children('span')removeClass(glyphicon glyphicon-plus glyph-plus-toggle).addClass(glyphicon glyphicon-minus glyph-minus-toggle);
Any idea where I am going wrong?
Thanks :)
.beforeremoveClassin your code also, are it just a typo while posting the question.