Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jquery script strange issue Re: jquery script strange issue

#104915
Mottie
Member

First off, don’t bind a click function inside of another click function. It just keeps adding more and more events the more you click on it.

I think the easiest solution would be to bind to all of the links inside the header and close (fadeOut) the header after the click. In this example, only the link with the class close would get a return false, preventing a window location change. All other links would execute. Here is an updated demo, and the code:

$("#header").hide();

$("#header").find("a").on("click", function() {
$(this).parents("#header").fadeOut("slow");
return $(this).hasClass('close') ? false : true;
});

$("a#toggle").click(function() {
$("#header").fadeToggle("slow", "linear");
});​