Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's make a working example from code you posted.</p> <p>The first thing I noticed is that both, the form and select tags have the same id attribute ( id value must be unique within the HTML document ), that’s why <code>"#portfolio-list"</code> selector don't work as expected, <code>change</code> event is triggered for the form and not for the select tag (if you are not sending data back to the server the form tag is not needed ).</p> <p>Furthermore, selectors for paragraps like <code>"#"+this.value</code> are starting with #, and options values start with # also, at the end the selector looks like <code>"##custom-exhibits</code>, and that is not a valid selector.</p> <p>In jQuery the <code>.val()</code> method is primarily used to get the values of form elements, <code>.value</code> is native JavaScript and although both methods are correct, if you are using jQuery then it is better to use his methods.</p> <pre><code>&lt;select name="portfolio-list" id="portfolio-list"&gt; &lt;option value="all" rel="all" class="current"&gt;All&lt;/option&gt; &lt;option value="custom-exhibits" rel="custom-exhibits" class="custom-exhibits"&gt;Custom Exhibits&lt;/option&gt; &lt;option value="permanent-installation" rel="permanent-installation" class="permanent-installation"&gt;Permanent Installation&lt;/option&gt; &lt;/select&gt; &lt;p id="all" &gt;paragraph1&lt;/p&gt; &lt;p id="custom-exhibits" &gt;paragraph2&lt;/p&gt; &lt;p id="permanent-installation" &gt;paragraph3&lt;/p&gt; &lt;script&gt; jQuery(function ($) { $("#portfolio-list").on( 'change', function(e) { // get selected option value var val = $(this).val(); // show element with that id $( '#'+val ).show(); // hide all other elements $('p').not( '#'+val ).hide(); }); }); &lt;/script&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. 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