I am looking for a toggle function that will open and close a <div>
when clicked. Check out this JSFiddle
HTML
<div class='answer'>answer</div>
<div style='display:none'>
<textarea name='talking'></textare>
<input type='submit'>
</div>
JQuery
$('.answer').click(function(){
if($(this).next().css('display','none')){
$(this).next().css('display','block');
}else if($(this).next().css('display','block')){
$(this).next().css('display','none');
}
})
In this scenario, the "if" statement works as intended to open the <div>
, but the "else if" statement does not successfully close it again.