Reputation: 3
I am fairly new to jQuery, and I was wondering if it's possible to select a div based on an image's source that is contained within? and remove the entire div if it finds an instance?
So in this example how would I look through all div's with a class of thumbnail for image
src="http://demo.com/wp-content/themes/TheStyle/timthumb.php?src=&h=180&w=222&zc=1&q=90"
and delete those divs?
<div class="thumbnail">
<a href="http://www.demo.com">
<img src="http://demo.com/wp-content/themes/TheStyle/timthumb.php?src=&h=180&w=222&zc=1&q=90">
</a>
<div class="date">
January 1st
</div>
</div>
Upvotes: 0
Views: 227
Reputation: 23142
Use the :contains() selector, like so:
$('div:contains(img[src=http://demo.com/wp-content/themes/TheStyle/timthumb.php?src=&h=180&w=222&zc=1&q=90])')
Upvotes: 2
Reputation: 359826
Use the :contains
selector.
$('div.thumbnail:contains(img[src="http://example.com/foo/bar"])').remove();
or select the <img>
and use .closest()
:
$('img[src="http://example.com/foo/bar"]').closest('div.thumbnail').remove();
Learn to dig through the jQuery API docs. They'll answer 99% of your questions.
Upvotes: 2