views:

162

answers:

1

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?

+2  A: 

Try: $(" > .subitem", evt.target).html()

The second parameter to the jQuery function provides context to the first parameter.

Please note that evt.target will be the actual element clicked; if you just want the specific .nav-item that was clicked, use $(this).

Shog9
Just some additional info for Arpit: The 'event.target' part is jQuery object, not a string. You are trying to concatenate an object with a string which definitely won't work.
KyleFarris