Akbar
Akbar

Reputation: 53

How to remove one of the image elemnt inside div using jquery

i have element div with id="akbarslide". There are four images inside.

<img src="image_suspetio/garbage.jpg" alt="garbage.jpg" width="270" height="250" />
<img src="image_suspetio/dog.jpg" alt="dog.jpg" width="270" height="250" />
<img src="image_suspetio/bar.jpg" alt="bar.jpg" width="270" height="250" />
<img src="image_suspetio/sky.jpg" alt="sky.jpg" width="270" height="250" />

I tried the code below, but images weren't removed.

$('img[src="garbage.jpg"]').remove();

Upvotes: 0

Views: 9516

Answers (4)

Adil
Adil

Reputation: 148150

You can not use exact match as the src is not garbage.jpg but have to use Attribute Ends With Selector, $ or contains garbage.jpg Use * for Attribute contains selector

$('img[src*="garbage.jpg"]').remove();

If you are certain that the src endwith garbage.jpg, you can use $

$('img[src$="garbage.jpg"]').remove();

Upvotes: 3

Lance
Lance

Reputation: 4820

 $("#akbarslide img[src*='image_suspetio/garbage.jpg']").remove();

Upvotes: 1

anacarolinats
anacarolinats

Reputation: 667

try:

$('img[src$="garbage.jpg"]').remove();

It will find the image whith the src ends with garbage.jpg

Upvotes: 1

Alvaro
Alvaro

Reputation: 41605

You can do it with this:

$("img[src$='garbage.jpg']").remove();

Living demo: http://jsfiddle.net/D9Hxk/

Upvotes: 1

Related Questions