javascript tutorial - [Solved-4 Solutions] Get the children of the $(this) selector - javascript - java script - javascript array
Problem:
How can we get the child img using a selector ?
Solution 1:
The jQuery constructor accepts a 2nd parameter called context
Which is the same as using .find()
like this:
If the imgs we desire are only direct descendants of the clicked element, we can also use .children()
:
Solution 2:
We could also use
which would return all imgs that are descendants of the div
Solution 3:
If we need to get the first img
that's down exactly one level, we can do
Solution 4:
If we DIV tag is immediately followed by the IMG tag, we can also use: