我有很多链接看起来像这样:
<a href="http://www.youtube.com/user/nigahiga">Youtube</a>
<a href="http://pinterest.com/pin/41236152807615600/">Pinterest</a>
<a href="https://www.facebook.com/manchesterunited">Facebook</a>
<a href="http://www.youtube.com/user/RayWilliamJohnson">Youtube</a>
<a href="http://pinterest.com/pin/24910604158520050/">Pinterest</a>
我如何才能只设置将链接到 pinterest
的超链接的样式。我试过这个:
$('a').attr('href').contains('pinterest').css('Styling here');
但它不起作用。如何实现?
最佳答案
您可以使用 attribute contains selector :
$('a[href*="pinterest"]').css('color','DeepSkyBlue');
或者更好的是只需要纯 CSS:
a[href*="pinterest"] {
color: DeepSkyBlue;
}
关于javascript - 如何设置特定标签的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16215797/