Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
120
rated 0 times [  121] [ 1]  / answers: 1 / hits: 28538  / 10 Years ago, thu, october 16, 2014, 12:00:00

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 ?


More From » firefox

 Answers
27

As far as i known clicking the children elements won't work because it is nested inside a button. A button is not container for child elements - only for text.



If you try like below it always tell that you clicked the button.





<button type=button onclick=alert('You clicked the button!');>
inside a button <span onClick=alert('clicked span');>**Not working**</span>
</button>





So, my suggestion is to use another span or a div





<div class=button_replace>
inside a div <span onClick=alert('clicked span');>**working**</span>
</div>





Hope it helps...



Note: Your code will work in chrome but not in firefox and my answer is alternative solution for making work in firefox


[#69105] Monday, October 13, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parker

Total Points: 259
Total Questions: 109
Total Answers: 97

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;