开发者

Anchors based tab navigation jquery code not working

var url = document.location.toString();
        if (url.match('#')) { // the URL cont开发者_运维技巧ains an anchor
          // click the navigation item corresponding to the anchor
          var myAnchor = '#' + url.split('#')[1];
          $("ul.tabs li").removeClass("active"); //Remove any "active" class
          $("ul.tabs li a:" + myAnchor).addClass("active"); //Add "active" class to selected tab
          $(".tab_content").hide(); //Hide all tab content
          $(myAnchor).fadeIn(); //Fade in the active ID content
        }

Why is the "li" element not being made active

Try accessing => http://domainsoutlook.com/s/site/stackoverflow.com.html#meta_info

Anchors based tab navigation jquery code not working


Your selector to get the tab is off. Your selector is "ul.tabs li a:#meta_info", which is not a real selector. You want to find the a with an href of "#meta_info". Try this instead:

$("ul.tabs li a[href='" + myAnchor + "']")


You're adding the class to the anchor, not the li.

Try this instead:

$("ul.tabs li a:" + myAnchor).parent().addClass("active");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜