jQuery - uncheck input type "checkbox" programmatically inside each( )

in jQuery, how do I change this:

<input type="checkbox" checked="" style="width:100px;float:left;" value="1">

or this:

<input type="checkbox" checked style="width:100px;float:left;" value="1">

to this:

<input type="checkbox" style="width:100px;float:left;" value="1">


I want to programmatically uncheck all checkbox type inputs that are children of a div...


so far:

 function CheckAllRights(checkthem) {       

        $('#gridRightsList input').each(function () {
     
?????

        });
    }

Open in new window

LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
Rainer JeschorCommented:
Hi,
this should work:
$("input:checkbox","#gridRightsList").removeAttr('checked');

Open in new window

Sample:
http://jsfiddle.net/EE_RainerJ/x6b231s6/

HTH
Rainer
0
 
Tom KnowltonWeb developerAuthor Commented:
YTH   (yep, that helped)   : )

My final version:

function CheckAllRights(checkthem) {     
        if (checkthem == "no") {
            $('#gridRightsList input:checked').removeAttr('checked');
        }
        else {
            $('#gridRightsList input').attr('checked','checked');
        }
    }

Open in new window

0
 
Tom KnowltonWeb developerAuthor Commented:
Thank you!

Tom
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Tom KnowltonWeb developerAuthor Commented:
Actually, stop the train..

My "Select All" only works once.  After that it stops working.
0
 
Rainer JeschorCommented:
Hi,
wrong selector :-)

Please use
input:checkbox

Open in new window

instead of
input:checked

Open in new window


And that's for free :-)
0
 
Tom KnowltonWeb developerAuthor Commented:
And that's for free :-)


Nice!



Now it works consistently:

    function CheckAllRights(checkthem) {     
        if (checkthem == "no") {
            $('#gridRightsList input:checkbox').removeAttr('checked');
        }
        else {
            $('#gridRightsList input').prop('checked','checked');           
        }
    }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.