I have a script which involves a click function and it always takes me to top of the page. I tried returning false as well as event.preventDefault() function but none seem to work. Here is my code: http://jsfiddle.net/79Rzh/14/
Please help.
Thanks in advance.
If it’s ok with you get the tab’s ID from another property, like
data-tabor something;HTML:
Javascript:
Working example.
When you set the
hrefattribute toactiveTabvariable you actually get the whole URL likehttp://somedomain.com/#tab2and when you try to use that variable to select elements you actually doing this:$('http://somedomain.com/#tab2')That’s why it doesn’t work withhrefattribute. HTML5 data attributes with jQuery.data()method works well in this kind of situations.