I have a radio button inside a content editable div. But when I click on the radio button nothing happens in Firefox and IE. But it works fine in Chrome.
What can I do to make this work in Firefox and IE?
The code is available at http://jsbin.com/uqexoy/2/edit and is simply:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div contentEditable="true"><input type="radio" />ere er er er re </div>
</body>
</html>
This was tested to work in IE8, IE9, Chrome and Firefox. It does work, albeit rather strangely so, also in Opera, where the
input field(in our case aradio button) does change it’s status tochecked(tested with JavaScriptalert(this.checked);), however it doesn’t change it’s appearance to reflect that. See for a possible workaround below.The solution for the majority of the problematic browsers is to wrap non-editable contents in a
span, like so:As for the Opera part, the fact that it doesn’t reflect changes to the
radio button‘sselectedstate ‘should’ be possible to override by styling its two different states with CSS selectorsinput[type="radio"]andinput[type="radio"]:checkedand applying these two CSS rules only to Opera browsers. Opera seems to acceptbackground-colorproperty changes for suchradio buttons, which doesn’t make any difference in all other browsers I’ve tested in. This might be your way to apply Opera specific CSS rule to reflect changes to thecheckedstate. Here’s an example:Other browsers will simply ignore this CSS rule. Another acceptable Opera specific rule that can be applied is
border, but I find that of limited to no value in our case.