Reputation: 13548
How do you use the .children()
jQuery method to get an image element? Is it .children('img')
?
Upvotes: 0
Views: 7333
Reputation: 172
.children('img')
can be used to get all children of an element with the tag img
.
See the documentation for more detail.
Upvotes: 0
Reputation: 437424
Yes, it is. For example:
<div id="foo">
<img id="image1" src="blah.jpg" />
<img id="image2" src="blah.jpg" />
<img id="image2" src="blah.jpg" />
</div>
You can get the images by $("#foo").children("img")
if the images are immediate children of the <div id="foo">
.
Another, more concise way would be $("#foo > img")
-- it's identical to the above.
If the images are descendants but not immediate children of the list, you can use $("#foo img")
.
Upvotes: 2