Select both pages and corresponding tab in jquery

I have a link to a tab (tab1, tab2, tab3), and at the bottom of the page there is a link to a link to the page for each tab.

to highlight tabs

$(document).ready(function(){
  var str=location.href.toLowerCase();
     $(".tabs li a").each(function() {
         if (str.indexOf(this.href.toLowerCase()) > -1  ) {
            $("li.highlight").removeClass("highlight");
            $(this).parent().addClass("highlight");
         }
      });
})

to highlight a page

$(document).ready(function(){
   var str=location.href.toLowerCase();
   $(".paging li a").each(function() {
      if (str.indexOf(this.href.toLowerCase()) > -1  ) {
        $("li.hp").removeClass("hp");
        $(this).parent().addClass("hp");
      }
    });            
 }) 

Although the link to the link and the link to the tab were correctly highlighted for each function, how can I highlight the current tab (after clicking the link to the page) and the current page at the same time? can i use the above functions?

thank!

+5
source share
1 answer

yes, you can use the same functions, just bind the function to call the above functions to the page link tag, specify the html element identifier for example, <Div id="myId"></Div> and try this

$("myId").live('click',function(){
  // call whichever function you want to
 }) ;
+1
source

All Articles