Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Add a custom attribute to the options and keep the same values throughout the group.</p> <pre><code>&lt;select name="test" class="select" id="test" multiple="multiple" style="width: 100%;"&gt; &lt;option data-index="1" value="1" class="first"&gt;1&lt;/option&gt; &lt;option data-index="1" value="2" class="first"&gt;2&lt;/option&gt; &lt;option data-index="1" value="3" class="first"&gt;3&lt;/option&gt; &lt;option data-index="2" value="a" id="1" class="hidden second"&gt;a&lt;/option&gt; &lt;option data-index="2" value="b" id="1" class="hidden second"&gt;b&lt;/option&gt; &lt;option data-index="2" value="c" id="1" class="hidden second"&gt;c&lt;/option&gt; &lt;option data-index="2" value="x" id="2" class="hidden second"&gt;x&lt;/option&gt; &lt;option data-index="2" value="y" id="2" class="hidden second"&gt;y&lt;/option&gt; &lt;option data-index="2" value="z" id="2" class="hidden second"&gt;z&lt;/option&gt; &lt;option data-index="2" value="baz" id="3" class="hidden second"&gt;baz&lt;/option&gt; &lt;option data-index="2" value="bar" id="3" class="hidden second"&gt;bar&lt;/option&gt; &lt;option data-index="2" value="foo" id="3" class="hidden second"&gt;foo&lt;/option&gt; &lt;/select&gt; $("select#test").change(function () { //get the data-index attribute of the selected option var nIndex = $('option[value= '+ $(this).val()+']').attr('data-index'); //get all elements with the attribute data-index = nIndex $('option[data-index= '+ nIndex +']').removeClass("hidden"); $(".first").addClass("hidden"); }); </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.
 

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