Basically, I want to append a div to an li element on mouseenter, then append a separate div on mouseenter of another li element of the same parent ul. So if an li is hovered, append #div1, then if another li is hovered, append #div2.
This is what I have so far
$('ul > li').mouseenter(function (){
$('#div1').appendTo(this);
if (('ul > li').mouseenter().not(this)){
$('#div2')appendTo(this);
}
});
This only appends #div1 to the hovered li. How do I append #div2 if another li is hovered? The .not() selector doesn’t seem to be working. Thanks in advance.
I’d suggest the following:
The above is based on the assumption that you wish to append
#div1to the firstli, and#div2to all otherlielements.Edited in response to comment from OP (left below):
References:
appendTo().closest().index().