How can I programmatically check a checkbox in Coffeescript ?
I know in Javascript, I can use this :
myElement.checked = true
Can I do something like the following in Coffeescript ?
myElement.checked "true"
I have already tried the above but it isn't working for me.
Any help in this regard will be highly appreciated. Thanks.
UPDATE:
myElement.checked = "yes";
myElement.checked = null;// for unchecking
So, for your case,
a.checked = b.checked; //i.e. check a if b is checked
Example here
//CoffeeScript
a = {}
a.b = 10
alert a.b
Compiles to..
//javascript
var a;
a = {};
a.b = 10;
alert(a.b);
However, a.b 10
compiles to a.b(10)
in javascript, which is not what you want. :)
Your myElement
is jQuery object and you want to address DOM element:
// HTML
<input class="toggle" type="checkbox"/>
//coffeescript
$('.toggle')[0].checked = true