I created a custom context menu that pops up when you click on an li
element within an unordered list. I'm trying to trigger an alert when clicking on an li
item inside the context menu, but it's not working as expected.
To handle this dynamic content creation, I used the jQuery function on
(replacing delegate()
):
$(".contextMenu").on("click", "li", function() {
var className = $(this).attr("class");
alert("Class name:" + className);
});
However, nothing happens when I click. I'm stuck and not sure what the issue is.
If you want to test it out, add the following script to your Tampermonkey extension:
// UserScript code goes hereYou can find the target page here.