How do we convert jQueryn $ li.find ('div.element: first') to VanillaJS

Does querySelectorAll () accept ('div.element:first')this type of argument? I need to convert below jQuery method in VanillaJS

jQUery:

$li = $(this)
$li.find('div.element:first')

Vanilla:

var li = event.target;
li.querySelectorAll('div.element:first');

But Vanilla script does not work the same as jQuery. Someone please suggest any best solution.

+4
source share
1 answer

jQuery :firstreduces the set of matched elements to the first in the set.

In other words, you get the first item matching div.element.

To do the same in simple javascript, all you have to do is call querySelectorwithout Allpart

var first = li.querySelector('div.element');

querySelector ,

, , , li , querySelector , jQuery find().

li , , ,

var first = li[0].querySelector('div.element');
+11

Source: https://habr.com/ru/post/1684158/


All Articles