admin管理员组文章数量:1318563
I have the following HTML structure:
<div><a href="link1">blah</a></div>
<div><a href="link2">blah</a></div>
<div><a href="link3.swf">blah</a></div>
<div><a href="link4">blah</a></div>
<div><a href="link5.swf">blah</a></div>
<div><a href="link6.swf">blah</a></div>
Using jQuery I want to retrieve the links that contain the .swf
extension and add a class to their parent div
element. Here is my code, which is not working:
$('a[href:contains(".swf")]').parent().addClass=('filmtrigger')
Can you help me fix this?
I have the following HTML structure:
<div><a href="link1">blah</a></div>
<div><a href="link2">blah</a></div>
<div><a href="link3.swf">blah</a></div>
<div><a href="link4">blah</a></div>
<div><a href="link5.swf">blah</a></div>
<div><a href="link6.swf">blah</a></div>
Using jQuery I want to retrieve the links that contain the .swf
extension and add a class to their parent div
element. Here is my code, which is not working:
$('a[href:contains(".swf")]').parent().addClass=('filmtrigger')
Can you help me fix this?
Share Improve this question edited Sep 28, 2017 at 15:24 Sven 1,5403 gold badges35 silver badges59 bronze badges asked Aug 18, 2010 at 4:43 Marcos BuarqueMarcos Buarque 3,4188 gold badges46 silver badges47 bronze badges 2-
:contains
only works for the contents inside a tag - the inner text of the tag. You're looking to match the value of an attribute (hint: Aaron provided the answer) – Erik Commented Aug 18, 2010 at 4:51 - Ok, thanks. Now I want to remove the <a> link, but keeping the text content that is inside it. I need to strip only the <a> tag that wraps it. What do you remend me to do? – Marcos Buarque Commented Aug 18, 2010 at 5:00
1 Answer
Reset to default 7$('a[href$="swf"]').parent().addClass('filmtrigger');
http://docs.jquery./Selectors
本文标签:
版权声明:本文标题:javascript - Using jQuery, find the links that contain a certain string and add a class - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742048237a2417919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论