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(); }); 

http://jsfiddle.net/9qjtct1x/


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -