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);     }); }); 

fiddle


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -