Hey so I’m not really knowledgeable with javascript and tried using ChatGPT to generate a script that allows elements in a field to display a pop up block with information upon being clicked. The elements are in a table if that information is needed as well.
const tableElement = document.querySelector("table");
// Add a click event listener to the table
tableElement.addEventListener("click", function(event) {
// Get the element that was clicked
const clickedElement = event.target;
// Only do something if the clicked element is a td
if (clickedElement.tagName === "TD") {
// Create the pop-up element and add it to the page
const popup = document.createElement("div");
popup.classList.add("popup");
popup.innerHTML = "This is the pop-up content!";
document.body.appendChild(popup);
// Position the pop-up next to the clicked element
const rect = clickedElement.getBoundingClientRect();
popup.style.top = `${rect.top + window.scrollY + 10}px`;
popup.style.left = `${rect.left + window.scrollX + 10}px`;
}
});
It created this but upon trying it doesn’t work. Any help with what is wrong with this?