Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function(){ //We attach an "onclick" event handler to our 1st checkbox here, as apposed to html code below for the input checkbox //This is the practice of separating display vs function $("#chkToggle1").click(function(){ //Call our toggleVisibility JS function, passing in a jQuery object for the row we want to hide, and a boolean indicating if our checkbox is checked or not toggleVisibility($("#trTarget1"), $(this).is(":checked")); }); //Again for our 2nd checkbox $("#chkToggle2").click(function(){ //Call our toggleVisibility JS function, passing in a jQuery object for the row we want to hide, and a boolean indicating if our checkbox is checked or not toggleVisibility($("#trTarget2"), $(this).is(":checked")); }); //Again for our 3rd checkbox $("#chkToggle3").click(function(){ //Call our toggleVisibility JS function, passing in a jQuery object for the row we want to hide, and a boolean indicating if our checkbox is checked or not toggleVisibility($("#trTarget3"), $(this).is(":checked")); }); }); //I created a generic function that can reused for toggle visibility of other objects, not locked down to just our table row //You'll note the first parameted has a "$" before it. This is to denote that the function is expecting a jQuery object and not a normal DOM object function toggleVisibility($targetObj, isVisible){ if(isVisible == true) $targetObj.show(); else $targetObj.hide(); } &lt;/script&gt; &lt;head&gt; &lt;body&gt; &lt;input type="checkbox" id="chkToggle1" checked="checked" /&gt; &lt;input type="checkbox" id="chkToggle2" checked="checked" /&gt; &lt;input type="checkbox" id="chkToggle3" checked="checked" /&gt; &lt;table style="border: 1px solid black;"&gt; &lt;tr id="trTarget1"&gt; &lt;td&gt;Table Row 1&lt;/td&gt; &lt;/tr&gt; &lt;tr id="trTarget2"&gt; &lt;td&gt;Table Row 2&lt;/td&gt; &lt;/tr&gt; &lt;tr id="trTarget3"&gt; &lt;td&gt;Table Row 3&lt;/td&gt; &lt;/tr&gt; &lt;table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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