Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is not a good practice to distinguish levels with spaces. Instead you should use a class or an id. This helps both the appearance (you can use css) and your code, since it defines logical levels.</p> <p>Edit your code to produce a DOM like that:</p> <pre><code>&lt;div class="level1"&gt; &lt;input id="$\$" class="featureTreeCheckbox" type="checkbox"&gt;$ &lt;div class="level2"&gt; &lt;input id="$\System" class="featureTreeCheckbox" type="checkbox"&gt;System &lt;div class="level3"&gt; &lt;input id="$\System\Library" class="featureTreeCheckbox" type="checkbox"&gt;Library &lt;/div&gt; &lt;div class="level3"&gt; &lt;input id="$\System\Configuration" class="featureTreeCheckbox" type="checkbox"&gt;Configuration &lt;div class="level4"&gt; &lt;input id="$\System\Configuration\Reimage" class="featureTreeCheckbox" type="checkbox"&gt;Reimage&lt;br/&gt; &lt;input id="$\System\Configuration\Installation" class="featureTreeCheckbox" type="checkbox"&gt;Installation &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Each "levelx" class defines a level. You can easily style it like this:</p> <pre><code>&lt;style&gt; .level1 { margin-left: 0px; } .level2 { margin-left: 10px; } .level3 { margin-left: 20px; } .level4 { margin-left: 30px; } &lt;/style&gt; </code></pre> <p>Then you can use code like this:</p> <pre><code>&lt;script type="text/javascript"&gt; $(function() { $('div.level1 input').change(function(event) { if ($(this).is(":checked")) { $(this).parent().find("input").attr("checked", "checked"); } }); $('div.level2 input').change(function(event) { if ($(this).is(":checked")) { $(this).parent().find(".level3 input").attr("checked", "checked"); $(this).parent().find(".level4 input").attr("checked", "checked"); } }); $('div.level3 input').change(function(event) { if ($(this).is(":checked")) { $(this).parent().find(".level4 input").attr("checked", "checked"); } }); }); &lt;/script&gt; </code></pre>
 

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