hyperlink - jquery toggle: clicking on link jumps back to top of the page -


I created a jquery toggle, but when I click on the link to open a div it is at the top of the page Will go How can I fix this?

I know that I can replace the link with anything else but I have to make it clear that it is a link and it can click on it.

/ div>

add return false; at the end of the code that you click on the link.

  $ ('a.myLink'). Toggle (function () {// my code returns false;});  

Alternatively, you can capture the event object, and call .preventDefault () .

  $ ('A.myLink'). Toggle (function) {event.preventDefault (); // run your code}}  

The default behavior of links is disabled by both of these methods.

The first also prevents the incident from bubbling, so only use it when you do not have any need to use the phenomenon of bubbling.


Comments