I have a layout similar to this:
<div id="..."><img src="..."></div>
and would like to use a jQuery selector to select the child img
inside the div
on click.
To get the div
, I've got this selector:
$(this)
How can I get the child img
using a selector?
You can use Child Selecor to reference the child elements available within the parent.
And the below is if you don't have reference to
$(this)
and you want to referenceimg
available within adiv
from other function.You could also use
which would return all
img
s that are descendants of thediv
Try this code:
Without knowing the ID of the DIV I think you could select the IMG like this:
You can use either of the following methods:
1 find():
2 children():