In my recent project, I am using the click event like so:
$(".nav-item").click(function(evt){
do something here...
})
Inside the event handler function, I want to look at the children of the event target using jQuery selectors. Something like
$(event.target + " > .subitem").html()
assuming .subitem was a childnode with a class subitem.
This doesnt seem to work. Any clues?
Try:
$(" > .subitem", evt.target).html()The second parameter to the jQuery function provides context to the first parameter.
Please note that
evt.targetwill be the actual element clicked; if you just want the specific.nav-itemthat was clicked, use$(this).