Skip to content
Advertisement

jQuery: Depending on the Selected Option of the Output a Different Text

I want a different output based on the selected option.

What I’m trying to do is if the selected option is beyond option 2, I want to enter the condition. If it’s not, don’t enter the condition.

This is my code:

JavaScript
JavaScript

Advertisement

Answer

You likely want to look at the selected option

JavaScript

but it is much simpler to use the DOM selectedIndex which is 0-based.

When you use this instead of $(this) you get the underlying DOM object

I am using a so-called ternary to set the text of the title

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement