I am trying to figure out the syntax for selecting a nth-child of an element by its class, however I don't know the exact path to the element. I can't do $('parent > child > grandchild > hereIam');
So basically I need to be able to say
$('#thisElement').AllRelativesWithClass('.classToSelect')
How exactly do I do that?
According to this documentation, the find method will search down through the tree of elements until it finds the element in the selector parameters. So $(parentSelector).find(childSelector)
is the fastest and most efficient way to do this.
$('#thisElement').find('.classToSelect')
will find any descendents of #thisElement
with class classToSelect
.
This should do the trick:
$('#thisElement').find('.classToSelect')
Try this
$('#thisElement .classToSelect').each(function(i){
// do stuff
});
Hope it will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With