I have a <button>
element inside of which I have 2 <span>
elements. I have 2 attached jquery click event handlers for each of the span elements so I can do whatever I like for each click. Here's a quick look of the basic code:
HTML
<button>
<span>Text1</span>
<span>Text2</span>
</button>
Javascript
$(function() {
$('button').bind('click', function() {
console.log('button clicked');
});
$('button > span:eq(0)').bind('click', function() {
console.log('text1 span clicked');
});
$('button > span:eq(1)').bind('click', function() {
console.log('text2 span clicked');
});
});
This is all working fine in Chrome and the click event is captured in the correct order: first on any of the span elements and then the event bubbles up to the parent button element.
The problem is that in Firefox the click event does not fire for any of the span elements, just the button event handler logs the event as being fired.
Here's a fiddle so you can see what I mean: http://jsfiddle.net/spider/RGL7a/2/
Thanks
A simple solution would be to use a <div>
element instead of a button element. Put the common code you want fired into a function and then execute the function when either of the spans are clicked as well as the span's unique code. If you wanted to be more 508 compliant you could make the spans into <a>
tags (or even <button>
tags.
Obviously, that doesn't explain FF event handling but it might be a quicker way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With