我正在尝试获取单击的锚标记的href,并将类添加到具有相同href的所有元素?
我知道如何向一个元素添加类,但是如何向具有相同href的所有元素添加类?
$('.shop-item').on('click', function(e){
var hrefz = $(this).attr('href'); //get the href on the clicked anchor tag
var otherElem = $('a[href$='+hrefz+']').attr('href');
alert(otherElem);
//$(this).addClass('newClass');
});
编辑:
HTML(这是hrefs的方式)
<ul class="shop-list">
<li class="shop-item"><a href="#Ordering"></a></li>
<li class="shop-item"><a href="#Delivery"></a></li>
....
</ul>
慕桂英3389331
相关分类