Reputation: 21
I need to toggle a checkbox-button in Jquery. assuming they are originally checkboxes, I tried
$("btn").attr('checked',true);
but did not function when the using checkbox as a button.
simply, I just want is to set the button below..
http://jqueryui.com/demos/button/#checkbox
like the checkbox is checked in example:
http://www.electrictoolbox.com/check-uncheck-checkbox-jquery/
--edit-- see the sample code..
<html><head>
<link type="text/css" href="css/smoothness/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
<script>
$(function() {
$( "#check" ).button();//when not a button it works .. just uncomment it.
$( "#check" ).attr("checked",true);//??
});
</script></head><body>
<input type="checkbox" id="check" /><label for="check">Toggle</label>
</body></html>
Upvotes: 1
Views: 4688
Reputation: 41433
$("btn").attr('checked','checked');
Also see Setting "checked" for a checkbox with jQuery?
Upvotes: 1
Reputation: 11028
try this...
$(".btn").attr('checked',true);
As i can see you are missing . or #
, depends upon whether btn
is id or class
Upvotes: 0
Reputation: 2163
you missed the dot from selector :P
$(".btn").attr('checked',true);
Upvotes: 0