0

I have two functions that I have made that check and uncheck all check boxes with a specific class. the first time I run the functions they do as expected but after I try to run the function again the check boxes do not check, but the html code changes.

JQuery...

function checkall() {
   $('.column').attr('checked','checked');
   $('#ALL').attr('onclick', 'uncheckall()')
   document.getElementById('ALL').value = "UnCheck All";
}

after running this I get <input type="checkbox" value="SEQN" class="column" onchange="updatearray()" checked="checked">

function uncheckall() {
   $('.column').removeAttr('checked');
   $('#ALL').attr('onclick', 'checkall()')
   document.getElementById('ALL').value = "Check All";
}

after running this I get <input type="checkbox" value="SEQN" class="column" onchange="updatearray()">

Why do the check-boxes only change once?

1
  • $('#ALL').attr('onclick', 'checkall()') isn't the proper way to add an event listener, if you're using jQuery then use it and don't do document.getElementById('ALL').value = "UnCheck All";, and .attr('checked','checked') should be .prop('checked',true) Commented Mar 23, 2016 at 18:22

1 Answer 1

4

Try prop() instead attr().If issue still persist iterate individual checkbox

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

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.