I'm trying to make sense of an API that listen if a "TAG" is clicked within a media player(called Wirewax) and return data on this element. My aim is to check if there is a certain string in the returned data and play an alert if that's the case.
1) I'm not familiar with the handling of the data parameter here but I managed to display the returned data on an html element:
<ul id="console"><ul>
and javascript:
const consoleOnScreen = document.getElementById("console");
const printOnScreen = data => {
const li = document.createElement("li");
li.innerHTML = `${data.name}: ${
data.data === undefined ? "no payload" : JSON.stringify(data.data)
}`;
consoleOnScreen.appendChild(li);
};
2) With the API reference for the eventListener:
`window.wirewax.addEventListener(
window.wirewax.events.listeners.TAG_CLICK,
function(data) {
printOnScreen(data);
}
);`
3) I tried a quick and dirty method to check if the html contained a certain string in the console element with
if (document.getElementById("console").innerHTML.includes("words")) {
alert('yep!');
}
but it doesn't find anything (probably because the content is not created yet).
Any ideas on how to manage that?