blah

Using jQuery, find links containing a specific string and add a class

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 get the links containing the extension .swfand add the class to my parent element div. Here is my code that does not work:

$('a[href:contains(".swf")]').parent().addClass=('filmtrigger')

Can you help me fix this?

+5
source share
1 answer
$('a[href$="swf"]').parent().addClass('filmtrigger');

http://docs.jquery.com/Selectors

+7
source

All Articles