JQuery toggle - an unexpected start

I'm new to jquery, I am writing a simple snippetto radio button menu. But the problem is this: when I look at the page bot and press the menu to switch. This is unexpectedly unexpected.

Thank you for reading.

+4
source share
3 answers

You probably have <a href="#">TEXT</a> as your link, right?

href="#" will cause the browser to scroll up, so add return false on click to make it look like this:

<a href="#" onclick="return false">TEXT</a> ; alternatively, you can return false from your click function to prevent default behavior.

+9
source

If the element is an anchor tag, grab the event object and call the preventDefault () method; as shown below.

 $('a#whatever').click(function (event) { event.preventDefault(); }); 
+2
source

OR <a href="javascript:;" class="toggle_this" >hello world!</a> <a href="javascript:;" class="toggle_this" >hello world!</a>

e.preventDefault() as Matt says it's good, of course!

+2
source

Source: https://habr.com/ru/post/1308527/


All Articles