How to select only one Select option?

Asked

Viewed 10 times

0

how do I select/change only my select Store 3 option? I need that by clicking Shop 3 it does some action, like change color, or add some effect on js.

$(function() {
        $('.filtro-compre').change(function(){
           $('.blocos').hide()
            $('.' + $(this).val()).show();
        });
    });
<style type="text/css">


.modelo {
    display: flex;
    justify-content: space-around;
}
.modelo div {
    width: 200px;
    height: 200px;
    margin-top: 30px
}

.varejo {
    background-color: red
}

.viagens {
    background-color: yellow
}

.servicos {
    background-color: gray
}
.blocos {
    display: none
}
</style>
<script
  src="https://code.jquery.com/jquery-3.4.0.min.js"
  integrity="sha256-BJeo0qm959uMBGb65z40ejJYGSgR7REI4+CW1fNKwOg="
  crossorigin="anonymous"></script>

<div class="form-master">

<div class="form-group"><select class="filtro-compre" id="list-lugar" name="unidade"><option disabled="true" selected="true" value="0">Ordenar por</option><option name="varejo" value="varejo">Loja 1</option><option name="servicos" value="servicos">Loja 2</option><option name="viagens" value="viagens">Loja 3</option></select></div>
</div>

<div class="modelo">
<div class="varejo blocos"></div>
<div class="servicos blocos"></div>
<div class="viagens blocos"></div>
</div>

  • Want to take effect on the option "Store 3"?

  • exactly, as I do?

  • 1

    You take the option value, compare in $('.filtro-compre').change(function(){ and does whatever you want if the value equals that of the option: if($(this).val() == "viagens"){ // faz alguma coisa }

  • Thanks man, that’s right, thank you very much.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.