-1
<select name="spell">
    <option value="Passive">Passive</option>
    <option value="Q">Q</option>
    <option value="W">W</option>
    <option value="E">E</option>
    <option value="R">R</option>
</select>
<script>
    $(document).ready(function(){
        if($('option[value=spell]')=='Q'){
            console.log('test');
        }
    });
</script>

I'm trying to check if Q is selected with Jquery and display 'test' in console

Hig
  • 33
  • 5
  • possible duplicate of [How to get jQuery dropdown value onchange event](http://stackoverflow.com/questions/19922729/how-to-get-jquery-dropdown-value-onchange-event) – KHeaney Feb 06 '15 at 17:26

1 Answers1

0

I would do it like this [example below]. This checks the value of the selected option.

DEMO http://jsfiddle.net/hy8c2unr/1/

$("select").on('change', function(){
    if($('select option:selected').val() === 'Q'){
        alert('test');
    }
});

Would also work

$("select").on('change', function(){
    if($(this).val() === 'Q'){
        alert('test');
    }
});
Kevin Lynch
  • 24,427
  • 3
  • 36
  • 37