What\'s the native equivalent of jQuery\'s $.fn.has?
For example, how would you write the following code:
$(\"li\").has(\"ul\").css(\"background-color\",
I would basically do it the way the jQuery specification for .has()
describes it, i.e. filtering the collection by trying to select the required element from the descendants of each element:
var liElements = Array.from(document.querySelectorAll("li"));
var liElementsThatHaveUl = liElements.filter(function(li) {
return li.querySelector("ul");
});
liElementsThatHaveUl.forEach(function(li) {
li.style.backgroundColor = "red";
});