How do I know if a particular "class" is in use on my page?

0

Friends,

There are many DIVs on my page, I need to check if any have not yet been "finalized", for example:

<div class="triagem"> conteudo a ser analizado</div> 

ready-made DIVs get another "class":

<div class="aprovada"> conteudo ja checado</div> 

I tried a JS but it did not work because I do not have the element, since there are hundreds and all of them with different IDs:

if(.hasClass("triagem");){
   //tratamento:
}

Another example that was not successful:

if(('[id^="triagem"]').classList.contains( 'triagem' ) ) {  
                 //tratamento:
            } 

So, my question is:  how to use java for confereir if you still have some div using the class "sorting"?

    
asked by anonymous 23.03.2016 / 07:34

1 answer

1

Roberval, first your html is wrong, would not it be:

<div class"triagem"> conteudo a ser analizado</div>  

But this:

<div class="triagem"> conteudo a ser analizado</div> 

You can use $('.triagem').size() .

var quantidadeTriagens = $('.triagem').size();
if (quantidadeTriagens > 0){
    console.log('Ainda existem triagens');
}else{
    console.log('Não existem mais triagens, vá para casa descansar.');
}

$('.triagem') will return a list with all the elements that have the sorting class. The size function will return the list size. The rest is history, if the size is 0 it does not have any, if it is greater than 0 it still exists.

    
23.03.2016 / 10:08