How to Check/Uncheck jquery-ui checkboxradio programatically
<p>I am trying to check/uncheck a <code>jquery-ui</code> <code>checkboxradio</code> 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 <code>jquery</code> and <code>jquery-ui</code> script tags and then create the widget dynamically:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Blank&lt;/title&gt;
    &lt;link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"&gt;
    &lt;script src="https://code.jquery.com/jquery-1.12.4.js"&gt;&lt;/script&gt;
    &lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>After the page loads, I hit <code>F12</code> to bring up dev-tools and enter the following commands to get a minimal <code>jquery-ui</code> checkbox:</p>

<pre><code>$container = $("&lt;div&gt;")
$container.append($("&lt;label for='chkbox'&gt;"))
$container.append($("&lt;input type='checkbox' id='chkbox'&gt;"))
$container.appendTo('body')
$('#chkbox').checkboxradio()
</code></pre>

<p>The checkbox is unchecked by default. Lets try to check it:</p>

<pre><code>$('#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...
</code></pre>

<p>This is irritating.  Does anyone have a solution to this seemingly simple problem?</p>