-1

All JavaScript event listeners on a WordPress site is pointing to the same snippet of code within a 'jquery.min.js' file:

function(a) {
  return "undefined" == typeof n || a && n.event.triggered === a.type ? void 0 : n.event.dispatch.apply(k.elem, arguments)
}

I have other JavaScript files with event listeners. However, Chrome nor Firefox shows them anymore? What could have caused this?

Asia x3
  • 606
  • 2
  • 16
  • 37

1 Answers1

1

If you use jQuery to add an event listener, jQuery attaches its own event dispatch function as an event listener for the element and adds your event listener to an event dispatch table that it maintains. When the event occurs jQuery's event dispatch function is called and looks up the event listeners in the event dispatch table and call those event listeners.

After doing some research I found the data structures for the jQuery event dispatch tables at How to find event listeners on a DOM node when debugging or from the JavaScript code?.

For the browser developer tools to display the event listeners added by jQuery instead of the directly attached jQuery dispatch function it must find and understand these jQuery event dispatch tables. If it cannot find or understand these jQuery event dispatch tables then the browser developer tools probably just gives up and shows the jQuery dispatch handler as a normal DOM event listener instead of the entries in the event dispatch table.

You can dump the first click event dispatch table entry for an element by running the console command:

jQuery(this).data('events').click[0]

In my browser for jQuery v1.12.4 this shows:

data: undefined
​
guid: 202
​
handler: function submitButtons()
​
namespace: "edit-post"
​
needsContext: undefined
​
origType: "click"
​
selector: undefined
​
type: "click"
​
<prototype>: Object { … }

Can you try this for an element with a click event handler in your browser by setting a breakpoint in the click event listener code for that element and running the above command in the console. My guess is that the structure of the event dispatch table is different and the browser developer tools either cannot find the jQuery event dispatch table or cannot understand the structure of the event dispatch table. jQuery has sometimes changed this data structure when it has released a new version.

  • Hi Magenta, I appreciate the help. I figured out that a few jQuery scripts were added to the website without my knowledge. So it appears these scripts are possibly overriding the jQuery version WordPress originally has, including my custom scripts? – Asia x3 Dec 06 '18 at 00:17