Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery, find the links that contain a certain 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 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?

like image 983
Marcos Buarque Avatar asked Aug 18 '10 04:08

Marcos Buarque


1 Answers

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

http://docs.jquery.com/Selectors

like image 102
Aaron Saunders Avatar answered Oct 06 '22 02:10

Aaron Saunders