I would like to be able to select both of these with a single css selector:
JavaScript
x
6
1
<div id= "someID">
2
<img src="images/leave-alone.png" class= "leave-alone">
3
<img src= "images/source.png" class= "foo bar">
4
<img src= "images/other-source.png" class= "foo zip">
5
</div>
6
Ideally, something like “class includes ‘foo'” to capture both those images at once. I know i can use .children().last().remove()
twice but I’d like to make sure my code is a bit more dynamic than that.
EDIT: realized I’m doing this on a click, so I’d like to be able to achieve the same thing with $(this)
as my jQuery starting point.
EDIT: I hacked it with $("#" + $(this).attr("id") + " img.foo").remove()
but maybe there’s something more elegant.
Advertisement
Answer
You can try this to select all images with class
foo
JavaScript
1
2
1
$("img.foo")
2
Or like this to select images with class
foo under div with id
someId
JavaScript
1
2
1
$("#someID img.foo")
2