Selecting a child div with a class inside an event handler
children, jquery, jquery-selectors, parent-child
Solution
This will select all children with the `.child` class.
$(".parent").mousemove(function() {
var children = $(this).children('.child');
});
With this you can select the first child with the `.eq()` method.
if (children.length > 0) {
var firstChild = children.eq(0);
}
You can also select from descendants (from children's children...) using the function `.find()`, not part of the question but related and useful to know.
var descendants = $(this).find('.child');
Problem
I am not sure on how to do this I have ``` <div class="a parent"> <div class="child"> </div> </div> <div class="b parent"> <div class="child"> </div> </div> ``` I want to something like this (in pseudocode) ``` $(".parent").mousemove(function(){ select the `.child` which is the child of this div }) ``` so when `.a` is hovered on it will select a's `.child` only, and when `.b` is hovered on it will select b's `.child` only This should involve `this` or `$this` or `$(this)` or something similar.. but its confusing and I don't know where to read about it