I have a bunch of nested lists:
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3
<ul>
<li>child-1</li>
<li>child-2
<ul>
<li>grand-child 1</li>
</ul>
</li>
</ul>
</li>
</ul>
With jQuery, with a click or hover, I want to use the item (li). But it gives me it's parent. As in: If I click (or hover) grand-child 1, $(this) returns ITEM-3 (parent's parent)
My jQuery code:
$('ul li').live('click', function(e) {
someVar = $(this).data("dataname"); // (can be .attr(""), etc.);
});
When any of the Li is clicked, how can I use that particular one and not the parent in which it's nested?
Would this help. if you see console.log, it only return the current clicked item. Read the documentation on stopPropagation here.
I also updated live to on, as live has been deprecated as of 1.7