Note that there are some explanatory texts on larger screens.

plurals
  1. POselect div not sibling using jQuery
    primarykey
    data
    text
    <p>I'm trying to expand a div when a checkbox is check but not sure best way to do it. I have multiple checkboxes on the page and want only the div below each checkbox to show. Here's what I have in the HTML:</p> <pre><code>&lt;!-- Start Topics --&gt; &lt;div id="topics"&gt; &lt;div class="box_heading"&gt; &lt;h2&gt;Topics&lt;/h2&gt; &lt;span class="line"&gt;&lt;/span&gt; &lt;/div&gt; IF CHECKED SHOW BELOW DIV &lt;div class="row"&gt; &lt;p&gt; &lt;label for=frmTopic"&gt;Check Me #1&lt;/label&gt; &lt;input type="checkbox" class="TopicCheckbox" name="frmTopic" id="frmTopic01" value="1"/&gt; &lt;/p&gt; &lt;/div&gt; SHOW THIS DIV IF CHECKED &lt;div class="row" name="divComment" id="divComment01"&gt; &lt;p&gt; &lt;label for="frmComment"&gt;Comment on Check Me&lt;/label&gt; &lt;textarea name="frmComment01" id="frmComment01" &lt;/textarea&gt; &lt;/p&gt; &lt;div class="row" name="fileUpload" id="fileUpload"&gt; &lt;input class="button green" type="file" caption="Choose files" name="file" id="file"&gt;&lt;br/&gt; &lt;/div&gt; &lt;/div&gt; IF CHECKED SHOW BELOW DIV &lt;div class="row"&gt; &lt;p&gt; &lt;label for=frmTopic"&gt;Check Me #2&lt;/label&gt; &lt;input type="checkbox" class="TopicCheckbox" name="frmTopic" id="frmTopic02" value="1"/&gt; &lt;/p&gt; &lt;/div&gt; SHOW THIS DIV IF CHECKED &lt;div class="row" name="divComment" id="divComment02"&gt; &lt;p&gt; &lt;label for="frmComment"&gt;Comment on Check Me&lt;/label&gt; &lt;textarea name="frmComment02" id="frmComment02" &lt;/textarea&gt; &lt;/p&gt; &lt;div class="row" name="fileUpload" id="fileUpload"&gt; &lt;input class="button green" type="file" caption="Choose files" name="file" id="file"&gt;&lt;br/&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Here's the jQuery which I can't get to work. Hopefully I'm close.</p> <pre><code>$('.TopicCheckbox').click(function() { if( $(this).is(':checked')) { //alert("clicked"); $(this).parent().find("div[name=divComment]").slideToggle('slow', function() { // Animation complete. }); } else { $(this).parent().find("div[name=divComment]").hide(); } }); </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.
    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