On select change, how do I pull the selected option’s ID and filter elements of the same class?

Tips and tricks from Tamara Olson Designs

A little jQuery is all that’s needed. (The select has the ID “change-work-category,” and the items to be filtered have the class “work-example-collage.”)


$('#change-work-category').change(function() {
$('a.work-example-collage').fadeOut();
$('.' + $(this).children(":selected").attr("id")).fadeIn();
});


Share Your Thoughts

About the Author

TamaraAuthorPhoto

Tamara Olson is a self-employed UX designer and WordPress developer living in New York City.

Tamara Olson Designs Case Studies