Richlewis
Richlewis

Reputation: 15384

Trigger event when clicking a paticular option value

I was wondering if the following is possible. I would like to fire different events depending upon which option is selected in a dropdown. So far I thought of this but nothing is happening when I select the option

$('#strand_id option[value="5"]:selected').on('click', function(){
  console.log('something just happened!!!')

});

I don’t think I can use the change method as this will apply the same event no matter what option is selected (unless there is a way?).

Upvotes: 0

Views: 33

Answers (1)

j08691
j08691

Reputation: 207953

Try this:

$('#strand_id').on('click ', function () {
    if (this.value == 5) console.log('something just happened !! !')
});

jsFiddle example

Upvotes: 1

Related Questions