I have the follow code in a js file:
$(".dropmenu").on("click", function(event){
event.preventDefault();
$(this).parent().find("ul").slideToggle();
});
And i have the follow code in my webpage:
var append="<ul>";
$.each(items, function(i, v){
append += "<li><a class='dropmenu' href='#'> Option </a>" +
"<ul>" +
"<li><a href='somelink'>somelink</a></li>" +
"</ul></li>";
}
$("div").append(append);
The point is when my ul tag its filled, the click event doesn't fire. I think because the class into anchor is dynamic.
How can I add the click event after the append function?