I want to get and modify the first child of the given element in an Angular directive.
<div class="wanted">
</div>
<div class="not-wanted">
</div>
<div class="not-wanted">
</div>
I already tried
elm.children('.wanted')
but then my directive modifies all children. How can I do this correctly?
You can either use:
elm.children().first();
or:
elm.children(':first')
Both will have the same effect. The second one is slightly more performant.
I use: element.children().eq(0)
children()
- Get the children of each element in the set of matched elements
eq()
- Reduce the set of matched elements to the one at the specified index
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