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 -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -