javascript - Once I remove an attribute I cant add it -
i trying make select checkbox when deselect , select again doesn't select boxes anymore. while work @ first time.
this code:
html:
<div id="everything"> <input type="checkbox" id="all" />select <br /> <br /> <div id="selectthese"> <input type="checkbox" id="first" />first <br /> <input type="checkbox" id="second" />second <br /> </div> </div>
js:
$(function () { $("#everything").on("click", "#all", function () { var carstatus = $("#all").is(':checked'); if (carstatus == true) { $("#selectthese input").attr("checked", "checked"); } else { $("#selectthese input").removeattr("checked"); } }); });
jsfiddle link: http://jsfiddle.net/epsju/1/
you'll need use prop()
that, , since accepts boolean check , uncheck element, can use variable directly, or ditch variable , use this.checked
:
$(function () { $("#everything").on("change", "#all", function () { $("#selectthese input").prop("checked", this.checked); }); });
Comments
Post a Comment