Losing selection when clicking checkbox label
I am trying to get a checkbox with a label to function so that when you have text selected in a contenteditable div
, clicking on the label
will not lose the selection from the div
. The label still needs to apply the standard checkbox tick/untick upon clicking it, but keep the focus & selection intack on the div
.
Doing a simple focus()
on the div
won't help as the selection will be gone (and caret is at the beginning). I could of course look into a way for storing the selection
object and trying to assign it b开发者_JAVA百科ack after the label
click, but isn't there any simpler way of keeping the selection
?
(the reason I need to do this with label
& checkbox
is because I will be using jQuery UI buttons and I will need the the toggle functionality of them)
On a similar note, if you click the checkbox, you usually still keep the selection in the answered belowdiv
, but at least on FF4, if you press the checkbox very frequently (<1s), it will lose the selection. Any idea what's going on there?
example: http://jsfiddle.net/niklasvh/gULM9/
It's a Firefox bug marked 490367.
According to the bug description, double-click functionality on input
fields will act unusually when there is a contenteditable div
on the page.
I noticed the strange behavior while trying to replicate it manually so I guessed it was a bug. I don't know of any workarounds.
精彩评论