javascript - Check the parent checkbox with jQuery -


Basically I'm trying to write a JS Funk that if I check a child check box, then checks the parents' checkboxes also, if not already checked

. I am using jQuery here my html:

  & lt; Ul id = "ulParent" style = "margin: 0; padding: 0; list-style: none;" & Gt; & Lt; Li style = "margin: 0 px 0;" & Gt; & Lt; Input type = "checkbox" check = "checked" class = "laser" id = "p1" /> Parents 1 & lt; Ul id = "ulParent" style = "margin: 0; padding: 0; list-style: none;" & gt; & Lt; Li & gt; & Lt; Input type = "checkbox" checked = "check" class = "li chald" id = "c1" onclick = "demand demand (this);" / & Gt; Child 1 & lt; / Li & gt; & Lt; Li & gt; & Lt; Input type = "checkbox" checked = "check" class = "li chald" id = "c2" onclick = "spinach (this);" /> Hair 2 & lt; / Li & gt; & Lt; Li & gt; & Lt; Input type = "checkbox" checked = "check" square = "li chald" id = "c3" onclick = "check parent (this);" /> Child 3 & lt; / Li & gt; & Lt; Li & gt; & Lt; Input type = "checkbox" check = "check" class = "li chald" id = "c4" onclick = "investigator (this);" /> Hair 4 & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li style = "margin: 0 px 0;" & Gt; & Lt; Input type = "checkbox" check = "check" class = "laser" id = "p2" /> Parent2 & lt; Ul id = "ulParent" style = "margin: 0; padding: 0; list-style: none;" & gt; & Lt; Li & gt; & Lt; Input type = "checkbox" checked = "check" class = "li chald" id = "c1" onclick = "demand demand (this);" / & Gt; Child 1 & lt; / Li & gt; & Lt; Li & gt; & Lt; Input type = "checkbox" checked = "check" class = "li chald" id = "c2" onclick = "spinach (this);" /> Hair 2 & lt; / Li & gt; & Lt; Li & gt; & Lt; Input type = "checkbox" checked = "check" square = "li chald" id = "c3" onclick = "check parent (this);" /> Child 3 & lt; / Li & gt; & Lt; Li & gt; & Lt; Input type = "checkbox" check = "check" class = "li chald" id = "c4" onclick = "investigator (this);" /> Hair 4 & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt;  

JS Func

  Function checkpati (hair) {if (child! = Null) {// If child has been checked, If there is a need to check (child.checked) {// Get the parents checkbox and do not check it ... .... Need help here .... $ (children) Parent (). Parent (). Parent () .... ..}}}}  

I Inline JavaScript will be removed and binding to bind check event:

  $ (document) .ready (function () {$ ('input.liChild'). Change (function (): {If ($ (this). (': Check')} {$ (this) .clostest ('ul'), siblings ('input: checkbox'). Et ('check', true);} });});  

This will tie up the event that you are looking for any input without the square Lee child, without all those oclics.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -