The issue with the code is that it doesn't target all i
elements that do not have a child font
element as intended. Instead, it selects all children of i
that are not font
elements.
console.log([...document.querySelectorAll('i>*:not(font)')])
<i>
<font color="008000">Here goes some text</font>
</i>
<br />
<i>Here goes another text</i>
To achieve the desired behavior, you should utilize the new :has()
selector in CSS which is supported by all major browsers (except for Firefox where it may require a flag to be enabled):
console.log([...document.querySelectorAll('i:not(:has(> font))')])
<i>
<font color="008000">Here goes some text</font>
</i>
<br />
<i>Here goes another text</i>