I need to validate the content of all li tags within a ul list. If any list item contains the text "None," then I want to append specific text to a div. If no li tag includes "None," then different text should be added to the div.
Upon checking my code, I encountered the following error in the console:
Uncaught TypeError: can't access property "includes", mylist.textContent is undefined
It appears that I may not be utilizing the .includes() method properly.
var mydiv = document.querySelector("#mydiv");
var mylist = document.querySelectorAll("#mylist li");
var myresult = mylist.textContent.includes("None");
if (myresult == true) {
mydiv.textContent = "Result is True";
} else {
mydiv.textContent = "Result is False";
}
My HTML:
<ul id="mylist">
<li>item 1</li>
<li>item 2</li>
<li>None</li>
<li>item 4</li>
<li>item 5</li>
<li>item 6</li>
<li>item 7</li>
</ul>
<ul id="mydiv">
</ul>