how to do show. () to more than one class at a time

1

Hello, I'm trying to do the following:

       $('.1','.btn').show();

I want to make visible only the div's that have those two classes together like this:

        <div class="1 btn"> 

I've tried doing it like this:

           <div class="1.btn"> 
           $('.1.btn').show();         

and it does not work either:

    
asked by sergipc88 29.01.2018 в 00:12
source

1 answer

2

It's really a mix of your solutions. The classes must be indicated in the html attribute separated by spaces:

<div class="1 btn">

And in the jQuery selector preceded by a point to indicate that it refers to a class and without separating:

$('.1.btn').show();

$(function(){
  $('#ocultar').click(function(){
    $('.1.btn').hide();
  });
  $('#mostrar').click(function(){
    $('.1.btn').show();
  });
});
div, button{
  padding: 10px;
}

div{
  border: 1px solid #666666;
  margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="1 btn">
  Div 1 btn
</div>

<div class="btn">
  Div btn
</div>

<div class="1">
  Div 1
</div>

<button id="ocultar">Ocultar</button>
<button id="mostrar">Mostrar</button>
    
answered by 29.01.2018 / 00:27
source