I've got a list that's got a mouseover
event bound:
myObject = function()
{
this.listTemplate = $("<ul></ul>")
.mouseover(function(event) {
//Do mouse over stuff
})
.click(function(event) {
//Do click stuff
});
//...more stuff
}
Later on in my code, I'm populating this list with items returned by an Ajax call, which all works swimmingly...
In the Ajax success method:
//...
$(items).each(function(item) {
$("<li />").append("<a />").text(item.value)
.appendTo(templateList);
});
//...
In my mouseover
event, the event.target
returns the anchor as expected, but I need the index of the li
ancestor (within the ul
) of the anchor I'm hovering over.
Given that the content of the li
could be more complex than just the anchor, does jQuery provide a simple way of finding that out?
i.e. I'm hovering over some descendent of li[0]
or li[4]
etc...