I need remove the attribute \"checked\" of one checkbox when errors occur.
The .removeAttr function not work. Any idea? :/
HTML
Both of these should work:
$("#captureImage").prop('checked', false);
AND/OR
$("#captureImage").removeAttr('checked');
... you can try both together.
using .removeAttr()
on a boolean attribute such as checked
, selected
, or readonly
would also set the corresponding named property to false
.
Hence removed this checked attribute
$("#IdName option:checked").removeAttr("checked");
try something like this FIDDLE
try
{
navigator.device.capture.captureImage(function(mediaFiles) {
console.log("works");
});
}
catch(err)
{
alert('hi');
$("#captureImage").prop('checked', false);
}
You could try $(this)
:
$("#captureAudio").live("change", function() {
if($(this).val() !== undefined) { /* IF THIS VALUE IS NOT UNDEFINED */
navigator.device.capture.captureAudio(function(mediaFiles) {
console.log("audio");
}, function() {
$(this).removeAttr('checked'); /* REMOVE checked ATTRIBUTE; */
/* YOU CAN USE `$(this).prop("checked", false);` ALSO */
_callback.error;
}, {limit: 1});
}
});
Sorry, I solved my problem with the code above:
$("#captureImage").live("change", function() {
if($("#captureImage:checked").val() !== undefined) {
navigator.device.capture.captureImage(function(mediaFiles) {
console.log("works");
}, function(exception) {
$("#captureImage").removeAttr('checked').checkboxradio('refresh');
_callback.error(exception);
}, {});
}
});
Try this to check
$('#captureImage').attr("checked",true).checkboxradio("refresh");
and uncheck
$('#captureImage').attr("checked",false).checkboxradio("refresh");