On WebKit browsers (I tested on Chrome and Safari on Mac), button element behaves weird:
Wen in this fiddle http://jsfiddle.net/5ReUn/3/ you do the following:
- Press left mouse button while the cursor is over HTML button text
- Move the cursor (while pressed) to an area of the button without text
- Release the mouse button
Then the click event on the button element is not fired!
HTML is very simple:
JavaScript
x
2
1
<button id="button">Click</button>
2
And the CSS is not sophisticated at all:
JavaScript
1
5
1
button {
2
display: block;
3
padding: 20px;
4
}
5
JS for click catching:
JavaScript
1
5
1
button = document.getElementById('button');
2
button.addEventListener('click', function() {
3
console.log('click');
4
});
5
Many visitors to my site complain that buttons are not clickable. They don’t realize they are moving the cursor while clicking.
Has anybody found a workaround for this?
Advertisement
Answer
It turns out to be a bug in WebKit.
An quick non-JavaScript solution is to wrap the text in a SPAN element and make it click-through:
JavaScript
1
4
1
<button>
2
<span>Click Me</span>
3
</button>
4
Example CSS:
JavaScript
1
6
1
span {
2
display: block;
3
padding: 20px;
4
pointer-events: none; // < --- Solution!
5
}
6
Since the bug appears only in WebKit, browsers that don’t support pointer-events
can be ignored.