html - jQuery uncheck all if "ALL" selected -


I have a checkbox that is generated based on the option from a table in my database, in that category, a default checkbox Want to create what is called "VIEW ALL", which was checked, should uncheck all other checkboxes, but if a check box is checked from within the range, then it should be kept in the existing ones, but "VIEW" must uncheck all "checkboxes

sample HTML:

   View all & lt; input type = "checkbox" name = "attr [1] []" class = "atri" value = "2" /> VALUE 2  VALUE 5 & lt; input type = "checkbox" name = "attr [1] []" class = "atri" Value = "6" /> VALUE 6  

Sample jQuery:

  & script; script type = "text / javascript" & gt; $ (Document) .ready (function () To add additional controls / category selector: $ (". Attr ") on (" change ", function () {var name = $ (this) .attr (" name "value = $ (this) .val (); if (val ===" ALL ") {$ (Name) .each (function (k, v) {$ (this) .removeAttr ("check");})} other {}});}); & lt; / script & gt;  

At this level, nothing happens, it does not select all at all.

Try the following:

HTML

  Input type =" checkbox "name =" attr [1] [] "class =" attr "value =" ALL "/> VIEW ALL $ (document) .ready (function () {// Category selector over To add individual controls: $ (". Attr"). ("Change", function () {var name = $ (this) .attr ("name"); var val = $ (this) .val ( ); If (val === "ALL") {$ ('input [name ^ = "attr"]'). ('Check', $ (this). This (": checked"));} });});  


Comments