This closes previous menu entry when I click on a new entry, but this does not work when I click the same entry again, menu stays open.
I don't know how the syntax is to check if previous and current entry are the same and only do the hide.
$(document).on("click", ".library-item-title", function (e) {
e.preventDefault();
var entry_id = $(this).data("id");
toggleDropdown(entry_id);
});
function toggleDropdown(entry_id) {
$(".library-edit-dropdown").hide("slow");
$("#library-edit-dropdown-" + entry_id).show("slow");
}
http://jsfiddle.net/patelmilanb1/LzaZT/1/
Can anyone help me?
You could use the toggle
and not
methods:
function toggleDropdown(entry_id) {
$(".library-edit-dropdown")
.not( $("#library-edit-dropdown-" + entry_id).toggle("slow") )
.hide("slow");
}
Note that above query can be expensive. You are using event delegation, probably this means you are generating the elements dynamically, but if caching is possible, you should cache the collection and reuse it.