I am trying to check/uncheck a jquery-ui checkboxradio widget programatically (i.e. without using the mouse). I've tried all manner of things but not joy. To reproduce the issue, choose a blank html page with just jquery and jquery-ui script tags and then create the widget dynamically:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blank</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
</body>
</html>
After the page loads, I hit F12 to bring up dev-tools and enter the following commands to get a minimal jquery-ui checkbox:
$container = $("<div>")
$container.append($("<label for='chkbox'>"))
$container.append($("<input type='checkbox' id='chkbox'>"))
$container.appendTo('body')
$('#chkbox').checkboxradio()
The checkbox is unchecked by default. Lets try to check it:
$('#chkbox').attr('checked', true) // nope
$('#chkbox').checkboxradio('refresh') // nope
$('#chkbox').attr('checked', false)
$('#chkbox').prop('checked', true) // nope
$('#chkbox').prop('checked', false)
$('#chkbox').addClass('ui-checkboxradio-checked') // not this either
$('#chkbox').removeClass('ui-checkboxradio-checked')
$('#chkbox').checkboxradio('option', 'classes.ui-checkboxradio-checked', true) // does nothing
$('#chkbox').checkboxradio('option', 'ui-checkboxradio-checked', true) // does nothing
$('#chkbox').checkboxradio('option', 'classes.ui-checkboxradio.ui-checkboxradio-checked', true) // and again, nothing...
This is irritating. Does anyone have a solution to this seemingly simple problem?