JSFiddle - React, Tailwind, and code Playground
HTML
<ul id="lista">
</ul>
JavaScript
function addlist2(nombre, fecha) {
var node = document.createElement("li");
var textnode = document.createTextNode(nombre + " ");
var textnode2 = document.createTextNode(fecha);
node.appendChild(textnode);
node.appendChild(textnode2);
document.getElementById("lista").appendChild(node);
// Add a listener to the node
node.addEventListener("click", clickHandler);
}
function clickHandler(e) {
// Get node content as a string
var nodeText = e.target.textContent;
// Trim whitespaces from the string and check if they match any criteria you like
switch (nodeText.trim()) {
case "dog":
// It's a dog! So do dog stuff here
alert("woof woof");
break;
case "bird":
// It's a bird! So do bird stuff here
alert("tweet tweet");
break;
default:
// Else, do stuff below
}
}
addlist2("dog", "");
addlist2("bird", "");