How do I convert a jQuery event target to a wrapped set?

In my recent project I am using click event like so:

$(".nav-item").click(function(evt){
    do something here...
})

      

Inside the event handler function, I want to look at the target's child objects using jQuery selectors. Sort of

$(event.target + " > .subitem").html()

      

Assuming .subitem was a child node with a class subtype.

This does not work. Any hints?

+1


a source to share


1 answer


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

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



Note that there evt.target

will be a click on the actual item; if you just want the specific .nav-item

one that was clicked use $(this)

.

+3


a source







All Articles