I have a single div
on a page. It has an onclick
event handler. When the user clicks on that div
I expect that the event handler will be called. But there is this CSS rule as well: when that div
has a focus, it will be moved 50 pixels to the right (away from the mouse pointer). As a result of this the onclick
event handler is not called, even though the user clearly clicked on that div
at the beginning. It's as if the browser first applies CSS and only after that decides, what did the user clicked on.
I made a simple demo here: https://jsbin.com/yalazam/edit?html,css,console,output Click on the yellow square (that is the div
) in the fourth column and see the console in the third column. Only a message "focus square"
will appear, but not a "click square"
.
Does this behavior makes any sense? Is there any case when it is useful? Or should I just accept it as a weird behavior of the browser?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/8u6HOro
Comments
Post a Comment