Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect several elements jQuery
    primarykey
    data
    text
    <p>I'm quite new to jQuery so don't jump me if this sounds stupid. I want to know if there is a way to select "#ammountbest2", the "input", and the "textarea" inside it so that I can hide and clear the values inside all at once, with one selector so I don't have to spell out every one. Something like siblings or parents. With that I could just attach at the end: ".val('').css('display', none')"</p> <pre><code>$('#ammountbest').change(function () { var ammountbest = "" $('#ammountbest option:selected').each(function () { ammountbest += $(this).text() + "";}); if(ammountbest == "0") {$('#ammountbest1,#ammountbest2').css('display', 'none');} if(ammountbest == "1") { $('#ammountbest1').css('display', 'block'); $('#ammountbest2 input,#ammountbest2 textarea').val(''); $('#ammountbest2').css('display', 'none'); } if(ammountbest == "2") { $('#ammountbest1,#ammountbest2').css('display', 'block'); } }) .trigger('change'); &lt;select id="ammountbest"&gt; &lt;option&gt;0&lt;/option&gt; &lt;option&gt;1&lt;/option&gt; &lt;option&gt;2&lt;/option&gt; &lt;/select&gt; &lt;!-- 1 Winners --&gt; &lt;div id="ammountbest1" style="display:none;"&gt; &lt;label for="besttitle1" title="Title"&gt;Title 01:&lt;/label&gt;&lt;br&gt; &lt;input name="besttitle1" id="besttitle1" size="30" type="input"&gt; &lt;label for="bestschool1" title="School"&gt;School 01:&lt;/label&gt;&lt;br&gt; &lt;input name="bestschool1" id="bestschool1" size="30" type="input"&gt; &lt;label for="bestvideo1" title="Video"&gt;Video Embed Code 01:&lt;/label&gt;&lt;br&gt; &lt;textarea name="bestvideo1" id="bestvideo1" cols="30" rows="5"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;!-- 2 Winners --&gt; &lt;div id="ammountbest2" style="display:none;"&gt; &lt;label for="besttitle2" title="Title"&gt;Title 02:&lt;/label&gt;&lt;br&gt; &lt;input name="besttitle2" id="besttitle2" size="30" type="input"&gt; &lt;label for="bestschool2" title="School"&gt;School 02:&lt;/label&gt;&lt;br&gt; &lt;input name="bestschool2" id="bestschool2" size="30" type="input"&gt; &lt;label for="bestvideo2" title="Video"&gt;Video Embed Code 02:&lt;/label&gt;&lt;br&gt; &lt;textarea name="bestvideo2" id="bestvideo2" cols="30" rows="5"&gt;&lt;/textarea&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.
    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