Initially, it's important to note that creating multiple instances of the specified div is not feasible due to the requirement for unique ids. To address this, one could consider utilizing a class name instead, like class="statusmenu"
. Additionally, determining which elements should display the menu below can be achieved by assigning them the class="status"
. In such scenario, the following script can be used to implement the menu:
$(document).on("click",'.status',function(){
if($(this).find('.statusmenu').length == 0){
var d = document.createElement("div");
d.setAttribute("class","statusmenu");
var ul = document.createElement("ul");
var li1 = document.createElement("li");
li1.innerHTML = "menu Item#1";
var li2 = document.createElement("li");
li2.innerHTML = "menu Item#2";
ul.appendChild(li1);
ul.appendChild(li2);
d.appendChild(ul);
$(d).hide();
this.appendChild(d);
$(d).slideDown();
}else{
$(this).find('.statusmenu').slideUp('fast',function(){ $(this).remove() });
}
});
Check out the demonstration on jsfiddle: http://jsfiddle.net/jakVp/