I'm playing around with some code and I'm almost there but i can't figure out this one last thing.
I'm using document.getElementsBy to look for a word in an Iframe, and it works. But when it finds the word it goes on to another Function.
I want it to send an Alert("not found") if it does not find the word.
function myFunction2() {
var iframe2 = document.getElementById("myFrame");
const allElements = iframe2.contentWindow.document.getElementsByTagName("li");
for (const element of allElements) {
console.log(element);
if (element.textContent.trim() === 'Tea') {
alert(element.textContent.trim());
}
}
}
You could just store whether you found 'Tea' in a boolean.
That would look something like this:
function myFunction2() {
var iframe2 = document.getElementById("myFrame");
const allElements = iframe2.contentWindow.document.getElementsByTagName("li");
let foundTea
for (const element of allElements) {
if (element.textContent.trim() === 'Tea') {
found = true
alert('Tea');
}
}
if (!foundTea) {alert('Not found')}
}