mayur dange
mayur dange

Reputation: 21

toggle jquery button as checked

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

Answers (5)

mayur
mayur

Reputation: 1

sorry, that's a bug in jquery; http://bugs.jqueryui.com/ticket/7476

Upvotes: 0

dotty
dotty

Reputation: 41433

$("btn").attr('checked','checked');

Also see Setting "checked" for a checkbox with jQuery?

Upvotes: 1

Vivek
Vivek

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

Treemonkey
Treemonkey

Reputation: 2163

you missed the dot from selector :P

  $(".btn").attr('checked',true);

Upvotes: 0

Blazes
Blazes

Reputation: 4779

You need to specify class or id... e.g: $("#btn")

Upvotes: 0

Related Questions