Skip to content
Advertisement

How to check for multiple values in a jquery IF statement

I have the below code which shows/hides a div based on an option in a dropdown, however it only toggles when a user selects 1. There are a few items in my dropdown that I’d like to show the DIV for. For example, let’s say I have values 1 through 8 in my dropdown, and I want to show a DIV when a user has selected 4, 6, and 7. I don’t want the DIV to toggle off and hide if a user changes selection from 4 to 6 either.

JavaScript

Advertisement

Answer

Use an array to store the “On” values and check that using the boolean display variable in jquery’s toggle:

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