Can I get event.target when there are nested jQuery calls

I am trying to find the event DOM target when there are nested jQuery calls. If there was only one level of call, then event.target would get the DOM target and I could go from there. But how to get through nested calls?

I am testing with a Javascript function

Read More
jQuery(document).bind('gform_post_render', function(event, formID){
    jQuery("#id").val(event.target.nodeName);
});  

I can look at event.target.nodeName and see that it is “#document”. I assume that is because the trigger which called this function was something like

jQuery(document).trigger('gform_post_render', ...);

And I think there is another level or two of calls above that.
What I’d like to be able to do is something like

event.trigger.event.trigger.closest(.classname).attr("attname");

although I realize that ‘event.target.event.target’ is not allowed.

Is there any way to do this?

BTW, what I am trying to do is extract a piece of data from the HTML that is going though a couple of WordPress plugins (popup and gravity forms) that do the jQuery calls. So I have no ability to change things, just trying to deal with what they did.

Related posts

1 comment

  1. You can pass a data argument to trigger, and then access it within the handler. So you pass it like this:

    $(document).trigger('gform_post_render', {target: event.target});
    

    and then in the handler:

    $(document).on('gform_post_render', function(event, data) {
        var target = data.target;
        ...
    });
    

Comments are closed.