1

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>
1

5 Answers 5

1

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

you missed the dot from selector :P

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

2 Comments

only if "btn" happens to be a class
no ... but sorry I edited it from $("#"+idd).. it even didn't work with single selector $("#fv")
0

try this...

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

As i can see you are missing . or #, depends upon whether btn is id or class

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.