问题描述:

what i am trying to do, when i click a tab, the address bar url should also change to that action plus it should also add the class to the anchor tag.

This is very nice example in jsfiddle, that i have seen someone shared on stackoverflow.

http://jsfiddle.net/VcQKr/2/

but problem here is that it works of adding and removing of class for li tag, but when i change this line

from

$parent.addClass("selected").siblings().removeClass("selected");

to

$t.addClass("selected").siblings().removeClass("selected");

then it only add classes to anchor tag but it dont remove classes from it??

网友答案:

That's because a elements are not siblings in your markup, you should select the siblings of the parent and remove the class from their a descendant elements.

$(this).addClass("selected")
       .parent()
       .siblings()
       .find('a')
       .removeClass("selected");

http://jsfiddle.net/FvxrL/

相关阅读:
Top