I am using slideToggle
jQuery function.which adds display: none
to the element.
But i need to add/remove classes(.displayNone/.displayBlock
) instead of adding style="display:block/display:none
to the element.
How to achieve it?.
$('button').click(function(){
$('p').slideToggle('normal');
})
$('p').toggleClass('displayNone displayBlock');////Adds 'displayNone', removes 'displayBlock' and vice versa
You need to add class to p element:
<p class="displayBlock">
If you want animation: use
opicity
anstransition
together, becausedisplay:none
does not work withtransition
.
Here is demo:
callback
function of slide toogle:
$('button').click(function(){
$('p').slideToggle('normal',function(){ $(this).toggleClass('displayNone displayBlock');});
})