Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery: Handling Checkbox Click Event with JQuery
    primarykey
    data
    text
    <p>I can't figure out what is going on here. I have some nested lists of checkboxes that I would like to check when the parent is checked. More importantly, I can't even get the alert to show up. It's as if the click event is not firing. Any ideas?</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $("#part_mapper_list input[type=checkbox]").click(function(){ alert("clicked"); if ($(this).attr("checked") == "checked"){ $(this + " input").attr("checked") = "checked"; } else { $(this + " input").attr("checked") = ""; } }); } &lt;/script&gt; &lt;link rel="stylesheet" href="style.css"&gt; &lt;div&gt; &lt;ul id="part_mapper_list"&gt; &lt;?php $makes = array("Audi", "BMW", "Mini", "Porsche", "Volkswagen"); $generations = array("Generation 1", "Generation 2", "Generation 3", "Generation 4", "Generation 5"); $modelclusters = array("Model Cluster 1", "Model Cluster 2", "Model Cluster 3", "Model Cluster 4", "Model Cluster 5"); $cars = array("Car 1", "Car 2", "Car 3", "Car 4", "Car 5"); foreach($makes as $mappermake){ echo "&lt;li id=\"" . $mappermake . "\" class=\"mapper_make\"&gt;+&lt;input type=\"checkbox\" name=\"mapper_make\" value=\"" . $mappermake . "\"&gt;" . $mappermake . "&lt;/input&gt;&lt;ul&gt;"; foreach($generations as $mappergen){ echo "&lt;li id=\"" . $mappergen . "\" class=\"mapper_gen\"&gt;+&lt;input type=\"checkbox\" name=\"mapper_gen\" value=\"" . $mappergen . "\"&gt;" . $mappergen . "&lt;/input&gt;&lt;ul&gt;"; foreach($modelclusters as $mappermodelcluster){ echo "&lt;li id=\"" . $mappermodelcluster . "\" class=\"mapper_modelcluster\"&gt;+&lt;input type=\"checkbox\" name=\"mapper_modelcluster\" value=\"" . $mappermodelcluster . "\"&gt;" . $mappermodelcluster . "&lt;/input&gt;&lt;ul&gt;"; foreach($cars as $mappercar){ echo "&lt;li id=\"" . $mappercar . "\" class=\"mapper_car\"&gt;&lt;input type=\"checkbox\" name=\"mapper_car\" value=\"" . $mappercar . "\"&gt;" . $mappercar . "&lt;/input&gt;&lt;/li&gt;"; } echo "&lt;/ul&gt;&lt;/li&gt;"; } echo "&lt;/ul&gt;&lt;/li&gt;"; } echo "&lt;/ul&gt;&lt;/li&gt;"; } ?&gt; &lt;input id="submit_mapping" type="submit"&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload