luv2code
luv2code

Reputation: 1296

How to get piece of img src from div and compare in jquery

Ok I know the title is a bit confusing but here is my problem: find all images containing image5.jpg and add a border to it. But I can not figure it out. Here is my code and below is the jsfiddle.

HTML:

<div class="picture"><img src="image.php/Marina/image5.jpg?width=650&height=650&image=/Marina/image5.jpg" /></div>
<div class="picture"><img src="image.php/Marina/image6.jpg?width=650&height=650&image=/Marina/image6.jpg" /></div>
<div class="picture"><img src="image.php/Marina/image7.jpg?width=650&height=650&image=/Marina/image7.jpg" /></div>

JQUERY:

$(".picture img:contains('image5.jpg')").css("border", "1px solid black");​

Any help would be greatly appreciated! Thanks so much. http://jsfiddle.net/7XUvw/11/

Upvotes: 1

Views: 264

Answers (4)

adeneo
adeneo

Reputation: 318372

$('img[src*="image5.jpg"]', '.picture').css("border", "1px solid blue");​

FIDDLE

Upvotes: 1

ClarkeyBoy
ClarkeyBoy

Reputation: 5010

Refer to http://api.jquery.com/attribute-contains-selector/

$(".picture img[src*='image5.jpg']").css("border", "1px solid black");​

should do it.

Upvotes: 1

Alex
Alex

Reputation: 35417

Utilize jQuery Attribute Selectors:

$('.picture img[src*="image5.jpg"]').css("border", "1px solid black");​

Upvotes: 1

Tomm
Tomm

Reputation: 2142

Try this

$(".picture img[src*='image5.jpg']").css("border", "1px solid black");​

See http://api.jquery.com/attribute-contains-selector/

Upvotes: 3

Related Questions