Skip to content
Advertisement

How to set a simple jQuery hide/show function to show all before hide?

I have a drop down selection, once it select it will show the div where the value and class share the same name and hide all else.

How can I have it so before you select it’ll show all and only hide after you select a option ?

EDIT I have updated the code snippet to run, have built in markup however on my local its php.

Revised question

how can I adjust my jQuery to show all, when none are selected and the selection is on default.

JavaScript
JavaScript

Advertisement

Answer

You can make a couple of changes:

  • use $(this).val() (this=select) to get the value= from the select option, no need to find option:selected and loop as .val() does this for you.

  • check for “all” then don’t apply the filter

  • as noted in the comments, “one”/”two” were around the wrong way (no impact on functionality, just makes it look like it’s wrong)

Updated snippet:

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