html - jquery .toggle event activating -
i have jquery program @ jsfiddle, , need because me jquery automatically calls .slideup(). can me this? want when click hyperlink hides test text , when clicked again shows it. problem code using .slideup() on hyperlink. do?
html:
<a href="#test">test</a>
<div id="test">test text</div>
jquery:
$('a').toggle(function () {
var box = $(this).attr('href');
$(box).slideup();
}, function () {
var box = $(this).attr('href');
$(box).slideup();
}
the toggle event method deprecated in jquery 1.8 , removed in jquery 1.9, using toggle effect method toggles visibility of elements. can use slidetoggle method instead:
$('a').on('click', function () { $(this.hash).slidetoggle(); });
Comments
Post a Comment