treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Highlight selected tab

  • I am using tabbed navigation using jquery.I have used this tutorial from "css-tricks".But I want to modify this code so that I can highlight active tab.I have coded click event of anchor tag, but it is not working.Please help me, Thanks in advance.
    anchor tag click event code added by me is:

    		$("div.hoverBtn").children("a").click(function(){
    $(this).parent().children("div")
    .stop()
    .css({"display": "block", "opacity": "1"})
    .fadeIn("fast");
    });
  • I normal add or remove a class with jquery and then just style .active{} to be what you want it to look like when active
  • I agree with karlpcrowley. Also, I think this can happen automatically somewhat like this:
    $(document).ready(function(){
    $currenturl = location.href;
    $('a[href=$currenturl]').addClass('selected');
    });
  • don't forget to removeClass before you at the 'selected'
  • thank u karlpcrowley and schart.That worked perfectly.
  • sagy_1991, can you post the code here please? i'm trying to highlight a tab that links to the same page (top, middle, bottom). but i can't get to work.

    thanks in advance.