javascript - Get value of select and use this to display div jquery -



javascript - Get value of select and use this to display div jquery -

i have select 2 options within:

<select id="type"> <option value="1">one</option> <option value="2">two</option> </select>

what want display hidden div when alternative 2 set.

so need grab value select , if equals 2, show div.

my effort jquery far follows:

$('#type').on('change', function(){ if(this.value == 2){ ('#hiddendiv').show(); } })

i'm including jquery, nil happening.

any ideas?

thanks!

apart obvious typo, think implementation should below because if select alternative 1 1 time again might want hide div

class="snippet-code-js lang-js prettyprint-override">//dom ready handler jquery(function($) { $('#type').on('change', function() { $('#hiddendiv').toggle(this.value == 2); }) }) class="snippet-code-css lang-css prettyprint-override">#hiddendiv { display: none; } class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <select id="type"> <option value="1">one</option> <option value="2">two</option> </select> <div id="hiddendiv">hiddendiv</div>

javascript jquery html css

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -