Im trying to rewrite the following function for event delegation:
$("ul > li.closed").click(function (e) {
if (e.target === this) {
var li = $(this).closest('li');
li.find(' > ul').slideToggle('fast');
$(this).toggleClass("closed open");
}
});
All the other functions I've rewritten run perfectly, but this one doesn't. Here is what I wrote:
$(document).on("click", "ul > li.closed", function (e) {
if (e.target === this) {
var li = $(this).closest('li');
li.find(' > ul').slideToggle('fast');
$(this).toggleClass("closed open");
}
});
As you can see, I didn't really change a lot. The ul opens, but doesn't close anymore. Where is my mistake?