How to know if a certain "class" is in use on my page?

Asked

Viewed 242 times

0

Friends,

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

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

Ready Divs get another "class":

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

I tried a JS but it didn’t work because I don’t have the element, since there are hundreds and all with different ID:

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

another example that I did not succeed:

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

So, my question eh: how to use java to check if you still have any dives using the "triage class" ?

1 answer

1


Roberval, first your html is wrong, wouldn’t that be it:

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

but yes 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 of all elements that have the triage class. The function size will return the size of the list. The rest is history, if the size is 0 there’s none, if it’s bigger than 0 exists yet.

  • Oh yes... Thank you! was a typo of this example... SOMETHING ELSE: I could repeat how to use the example { $('.screening'). size(). } don’t understand?!?! how to use with an IF please!

  • 1

    Sure, I’ll explain it better.

  • 1

    Take a look to see if it’s clearer now.

  • It was very easy to get bored! I don’t know how to thank you!!! I’ll test now! SAME BRIGADE!... something else.. where you are at that time of the morning writing code to others?

  • I’ve been living in India for a while, so here’s 3PM ;)

  • when Voce puts a "console.log"?

  • my dear ... I think I’m eating ball.. I thought I was wrong about the typing.. but that’s correct.. it always returns "0" or empty.... I’ve run several tests... on the console for exeplo give a "$('.memo-list-check')" and it returns 2... what you think might be?

Show 2 more comments

Browser other questions tagged

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