robert_gsfame Posted July 9, 2010 Share Posted July 9, 2010 i have a tab menu let say tab1,tab2 and tab3 and i have this <a href="#tab1">tab1</a> to open the first tab there is no problem actually with the tab itself only i always get back to the top of the page after the chosen page open, can i avoid this like when using javascript:void(0) Quote Link to comment Share on other sites More sharing options...
joel24 Posted July 9, 2010 Share Posted July 9, 2010 use html anchor tags, http://www.hypergurl.com/anchors.html#bottom i.e. <html> <body> <a href='#tab1'>Tab1 Content</a> <br /> <br /> <br /> <br /> <br /> <br /> <br /><br /> <br /><br /><br /><br /><br /> <br /> <br /> <br /> <br /> <br /> <br /><br /> <br /><br /><br /><br /> <a name='tab1'>Tab1 Content:</a><br /> Rarrarararar etc etc etc. </body> </html> Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted July 9, 2010 Author Share Posted July 9, 2010 If u use anchor then they will go to where the anchor is, i just dont want to go anywhere Quote Link to comment Share on other sites More sharing options...
joel24 Posted July 9, 2010 Share Posted July 9, 2010 You don't want the link to go anywhere? You can have something like <a href='#'>Link</a> or, if you want the link to go to a certain point on a new page - say home.html then have the anchor tag on the page somewhere so the link would be home.html#anchor and the html home.html <html> <body> <br /> <br /> <br /><br /> <br /><br /> <br /> <br /> <br /> <br /> <br /> <br /><br /> <br /><br /><br /><br /> <a name='anchor'>Content Here:</a><br /> Rarrarararar etc etc etc. </body> </html> If this isn't right, I don't understand what you're after. What are you after? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 10, 2010 Share Posted July 10, 2010 How are you opening the tabs? Are you using the onclick event handler in the link? If so, then just use void: <a href="javascript: void(0);" onclick="javascript: changeTab('home');">Home</a> It's hard to say without seeing more of your code or knowing how your achieving the tabs. Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted July 10, 2010 Author Share Posted July 10, 2010 <script type="text/javascript"> $(document).ready(function() { //Default Action $(".tab_content").hide(); //Hide all content $("ul.tabs li:first").addClass("active").show(); //Activate first tab $(".tab_content:first").show(); //Show first tab content //On Click Event $("ul.tabs li").click(function() { $("ul.tabs li").removeClass("active"); //Remove any "active" class $(this).addClass("active"); //Add "active" class to selected tab $(".tab_content").hide(); //Hide all tab content var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content $(activeTab).fadeIn(); //Fade in the active content return false; }); }); </script> n i have this html code <ul class="tabs"> <li><a href="#tab1">Tab1</a></li> <li><a href="#tab2">Tab2</a></li> </ul> <div id="tab1" class="tab_content">blablabla</div> <div id="tab2" class="tab_content">blablabla</div> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 10, 2010 Share Posted July 10, 2010 In that case. You're returning false on the list, which won't do anything. You'll need to do some re-arranging. Try this: $("ul.tabs li a").click(function() { $("ul.tabs li").parent().removeClass("active"); //Remove any "active" class $(this).parent().addClass("active"); //Add "active" class to selected tab $(".tab_content").hide(); //Hide all tab content var activeTab = $(this).attr("href"); //Find the rel attribute value to identify the active tab + content $(activeTab).fadeIn(); //Fade in the active content return false; }); Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted July 10, 2010 Author Share Posted July 10, 2010 not working?? it always goes back to the top of the page when new tab open :confused: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.