Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent anchor link from being added to URL

I have a tabbed content box that when a tab is clicked, a '#div1' is appended to the end of my URL. Is there a way of preventing jQuery from doing this?

I still can't get it to work. I've made a fiddle...

http://jsfiddle.net/k6Ks8/

like image 573
Liam Avatar asked Jan 27 '12 14:01

Liam


People also ask

Can we disable anchor tag?

Disable HTML Anchor Tag with CSSThe best way to disable a link tag is by using the CSS property pointer-events: none; . When you apply pointer-events: none; to any element, all click events will be disabled. Because it applies to any element, you can use it to disable an anchor tag.

How do I block an anchor tag?

To disable a HTML anchor element with CSS, we can apply the pointer-events: none style. pointer-events: none will disable all click events on the anchor element. This is a great option when you only have access to class or style attributes. It can even be used to disable all the HTML links on a page.

How could you prevent a click on an anchor from going to the link?

How could you prevent a click on an anchor from going to the link? To prevent an anchor from visiting the specified href, you can call the Event interface's preventDefault() method on the anchor's click handle.

Is anchor part of URL?

The anchor part is the part of the URL after the hash sign (#).


1 Answers

Sure, event.preventDefault() is what you are looking for.

http://api.jquery.com/event.preventDefault/

like image 54
IProblemFactory Avatar answered Oct 26 '22 23:10

IProblemFactory