jQuery find similar attributes
My page has two 'tabbed' navigation sections. Both independent of one-another, but resulting in the same outcome. I figure the easiest way to go about coding them to work together, would be to find the `href' attribute that is th开发者_JS百科e same from both sections, save it in a variable, and than continue from there.
My layout looks something like this.
<div id="tab-text">
<a href="tab-1"></a>
<a href="tab-2"></a>
<a href="tab-3"></a>
</div>
<div id="tab-arrow">
<a href="tab-1"></a>
<a href="tab-2"></a>
<a href="tab-3"></a>
</div>
And i have some jQuery like this.
jQuery('#tab-text a').click(function()
{
jQuery('#tab-text a').removeClass('active');
jQuery( this ).addClass('active');
}
So how can i include in the jQuery if #tab-text a
is clicked, than find the value of the href
attribute, and than search for that value from #tab-arrow a
and .addClass()
jQuery('#tab-text a').click(function()
{
jQuery('#tab-text a').removeClass('active');
jQuery( this ).addClass('active');
var searchHref = this.href;
jQuery('#tab-arrow a[href="'+searchHref+'"]').doSomething();
}
精彩评论