Liam
Liam

Reputation: 9855

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/

Upvotes: 6

Views: 7042

Answers (2)

Mohsen
Mohsen

Reputation: 4235

easy

    $(function(){
        $('a[href="#"]').click(function(event){
            event.preventDefault();
        });
    });

Upvotes: 3

AbstractProblemFactory
AbstractProblemFactory

Reputation: 9811

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

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

Upvotes: 13

Related Questions