Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If a div has this two classes, hide wrapper

I have a wrapper that shows an image and a star. I want to hide the wrapper if both image and star has a class named "no". It has to be both, if just only one of them has the "no" class it has to be shown.

<div id="wrapper">
<a href="#" class="image no" target="_blank"><img src="something.jpg"></a>
<a href="#" class="star no"><img src="star.png"></a>
</div>

Something like this:

if ($(".image, .no") && $(".star, .no")) {
    document.getElementById("wrapper").style.display = "none";
}
like image 378
Kakotas7 Avatar asked Dec 19 '25 20:12

Kakotas7


2 Answers

.hasClass() is what you looking for

if ($(".image").hasClass("no") && $(".star").hasClass("no")) {
 // TODO
}

Even simpler

if ($(".image,.star").is(".no")){
  // TODO 
}
like image 184
Suresh Atta Avatar answered Dec 21 '25 11:12

Suresh Atta


You can also do it without jQuery:

if(document.querySelectorAll('.image.no').length && document.querySelectorAll('.star.no').length) { 
  document.getElementById("wrapper").style.display = "none";
}
like image 21
connexo Avatar answered Dec 21 '25 10:12

connexo