Your question ambiguity leaves me to cross answer this.
First off:
$('li.fas')
That says to the sizzle engine: Get all elements that have class fas
, then reduce that to elements of li
(that have that class)
With a space in between this says:
$('li .fas')
Get all elements that have a class fas
, then reduce to those that are a decedent of an li
element.
$('li>.fas')
Get all elements that have class fas
, then reduce that do a set that are direct children of an li
element.
The other answer has the .has()
so I will not repeat that.
Filter: (basically same as :has() in this case
$('li').filter(function(){
// reduce the li set; return true when a descendant has the 'fas' class
return !!$(this).find('.fas').length;
});
More on context here: https://stackoverflow.com/a/16423239/125981