tags:

views:

32

answers:

1

I have a page set up with tabs that includes the history function so it appends the url with the ID of each tab. Inside one tab I have a set of anchor tags, like a FAQ section. The problem is that the anchor ID's are messing up the url, it removes the tab ID from the URL and adds the anchor ID. Is there a way to turn off the URL redirecting for just the anchors? I would assume I could give a class to the anchors and target them that way but I dont have any idea on the rest of the code. thx

+2  A: 

as far as I understand your question, you want to stop the navigation from current page on clicking anchor tag ?

$(function() {
   $('a#scollToFaQ').bind('click',function() {
     var pos = $('#faq').offset().top;
     $('html,body').animate({scrollTop : pos}, 1000);

     return false;  //stops navigation
   });
});

Test the code , look at the address bar for url [you'll find that url isn't alterning]

Ninja Dude
No, right now they are in a tab "#tab1" and when I use the anchor tag that is inside "#tab1" to jump to a block of content also inside "#tab1" it changes my url from www.domain.com/#tab1 to www.domain.com#anchorID, I want to stop that from happening
Dirty Bird Design
fwiw you may need to localize this with an ID or a class if its only links in a specific section.
DannyLane
@DannyLane, I stated that in the last sentence of my question
Dirty Bird Design
+1 I already have code simalar to your updated answer (with the animate) being used in production atm, its a nice scrolling effect.
DannyLane
@Dirty Bird Design I noticed, thats why I was suggesting the answer should be updated.
DannyLane
@DannyLane - my bad, didn't see that. So is that your code in Avinash's answer?
Dirty Bird Design
@Dirty Bird Design, lol, no, I wasn't saying he stole code :) . Its not my code. Its a fairly standard way of doing that kind of animation in jQuery. I had a simalar default anchor/bookmark behaviour was causing problems for me aswell so I also ended up with a solution like this. You should try it, I think you'll be happy w it.
DannyLane
@DannyLane, @Avinash, didn't mean to imply he stole it, or anything like that. you were referring to your code, and that was the only code I saw. Thanks Avinash, this seems to be perfect. Much appreciated.
Dirty Bird Design
@DirtyBirdDesign lol, you're welcome. Have a Good Day !!
Ninja Dude