Dev1997
Dev1997

Reputation: 677

Target SELECT option JQuery

I am trying to target an option within a select dropdown through JQuery.

The HTML:

<select id="category-select" name="category">
    <option class="all" value="all">All</option>
    <option class="env-tech" value="environmental-technologies">Environmental Technologies</option>
    <option class="digital-media" value="digital-media">Digital Media</option>
    <option class="serv-consumer" value="services-consumer">Services/Consumer</option>
    <option class="bio" value="bio-technology">Medical/Biotechnolgy</option>
</select>

The JQuery

('#category-select option[value="environmental-technologies"]').click(function() {

    $('.portfolio-area').show().filter(':not(.environmental-technologies)').fadeOut(200);

 });

How do I achieve this? I have had no succes with other solutions on the site.

Upvotes: 1

Views: 857

Answers (1)

GunJan Mehta
GunJan Mehta

Reputation: 312

You can try doing

$(document).on("change","#category-select", function(){
    if($(this).val()=='environmental-technologies')
    {
        alert(1); // Your code $('.portfolio-area').show()....
    }
});

Upvotes: 2

Related Questions