admin管理员组

文章数量:1318766

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
Add a ment  | 

1 Answer 1

Reset to default 7
$('a[href$="swf"]').parent().addClass('filmtrigger');

http://docs.jquery./Selectors

本文标签: