Micah
Micah

Reputation: 4550

jQuery return all matched element, need to way to determine selected element

Please help to determine the element.

Please check my example http://jsfiddle.net/fantill/DFd7e/

I want to get return from all li after 2nd level but only selected one.

in css it should be ul ul li.

My problem is if I write above way, jquery will return all matched element not only the one I chooses.

Either $('#A').find('ul ul li') or $('#A ul ul li') are the same result.

Usually $(this) will be the chosen element, but I dont know why it doesnt work in this case.

Thank you very much for your advice and help.

Upvotes: 1

Views: 92

Answers (1)

Jamiec
Jamiec

Reputation: 136094

I think what you're looking for is to stop propagation of the event up to its ancestors.

$('#A').find('ul ul li').click(function(e){ 
    alert($(this).html());
    e.stopPropagation(); 
});

event.stopPropagation

Live example: http://jsfiddle.net/DFd7e/3/

Upvotes: 3

Related Questions