Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing click event for <span> inside <button> element on firefox

Tags:

I am experiencing problem with Firefox 32 when I bind action on click event of span element inside a button element. Other browsers seems to works well.

Here the code illustrating the issue on jsFiddle.

<span onClick="alert('test');">**Working**</span><br>  <button>inside a button <span onClick="alert('test');">**Not working**</span></button>

Does anybody know why and if it's a bug or a feature ?

like image 365
Jrmi Avatar asked Oct 16 '14 10:10

Jrmi


People also ask

Can we give Onclick to span?

When clicking on the p element, it will return both the p and the div element, since the p element is inside the div element. But when clicking on the span element, it will only return itself, and not the p and the div element (even though its inside these elements).

Can you put a span inside a button?

Blocks and inline elements cannot be placed inside a span (or any inline element), but a button can and is an inline element, so yes, that is the correct approach if you're looking for an inline element containing text and another inline element.

Can you have a div in a button?

All Elements Can Be ButtonsAny div, header, footer or other containers can be a w3-button!

What is the event target when clicking the button?

An element receives a click event when a pointing device button (such as a mouse's primary mouse button) is both pressed and released while the pointer is located inside the element.


1 Answers

You have to add the pointer-events property to the span element.

button span {   pointer-events: none; } 
like image 72
marco-s Avatar answered Sep 23 '22 07:09

marco-s