Click event not working on span close button

185 Views Asked by At

I've been adding click events in the contentscript.js of a chrome extension. All the click events work as expected except on one this span div which is a small x button to close an li element that acts as a tab in a page interface.


/// content script
$("body").delegate("span", "click", clickEventFunction);
/////////  HTML of page
<span role="button" id="close" tabIndex="0" style="margin-left:3px;vertical-align:top"></span>

I've attempted to add event listener rather than delegate. I've changed the selector to use the id or role. Nothing gets the click event. The same code works on every other element on the page and other span elements. Using plain javascript doesn't help either.

Is the element closing before the click event is registered?

2

There are 2 best solutions below

1
On

You need quotes around body:

/// content script
$(body).delegate("span", "click", clickEventFunction);

to

/// content script
$("body").delegate("span", "click", clickEventFunction);
0
On

wOxxOm suggestion worked. "Try listening in the capture phase to mousedown"