Note that there are some explanatory texts on larger screens.

plurals
  1. PO.attr('checked','checked') does not work
    primarykey
    data
    text
    <p>I am trying to check radio. Neither the following works:</p> <p>[edit]</p> <pre><code>$('selector').attr('checked','checked'); $('selector').attr('checked',true); </code></pre> <p>The two alert() in the following code show "1" and "a", respectively. My expectation is the second alert() showing "b".</p> <p>Opera does check the second radio box in its browser, but its element inspector, dragonfly, shows that the DOM is not changed.</p> <p>[end edit]</p> <p>I had read the FAQ before I posted this question:</p> <p><a href="http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_check.2Funcheck_a_checkbox_input_or_radio_button.3F">http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_check.2Funcheck_a_checkbox_input_or_radio_button.3F</a></p> <p>Helps will be much appreciated!</p> <p>TIA</p> <p>The xhtml page and code follows:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt; &lt;title&gt;Weird Behavior&lt;/title&gt; &lt;script type="text/javascript" src="scripts/jquery.js"/&gt; &lt;script type="text/javascript"&gt; function clickme(){ alert($('input[name="myname"][value="b"]').length); $('input[name="myname"][value="b"]').attr('checked','checked'); $('#b').attr('checked',true); alert($('input[name="myname"][checked]').val()); }; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form action=""&gt; &lt;fieldset&gt; &lt;legend&gt;Why check is not switched?&lt;/legend&gt; &lt;input type="radio" name="myname" value="a" id="a" checked="checked"/&gt;A &lt;input type="radio" name="myname" value="b" id="b"/&gt;B &lt;/fieldset&gt; &lt;/form&gt; &lt;p&gt; &lt;button type="button" onclick="clickme()"&gt;click me&lt;/button&gt; &lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload