Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  59] [ 4]  / answers: 1 / hits: 22309  / 9 Years ago, fri, august 21, 2015, 12:00:00

I have some problems with show/hide element. I have 2 popups on one page and I need hide one popup if another popup has class.
For example:



<body class=home>
<div class=popup main></div>
<div class=popup></div>
</body>


So, if body.home has .main I need to show only .main popup and hide or remove another .popup.



I'va tried



if ($('.home').find('.main')) {
$('.home').find('.main').show();
$('.home').find('.popup').remove();
}


But it does not working as I need, because in some reason I'll have code only with one popup block



<body class=home>
<div class=popup></div>
</body>

More From » jquery

 Answers
19

Just try this,





if($(.popup).hasClass('main')){
$(.popup).hide();
$(.main).show();
}

<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js></script>
<body class=home>
<div class=popup main>main</div>
<div class=popup>another</div>
</body>




[#65336] Wednesday, August 19, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
demondp

Total Points: 154
Total Questions: 97
Total Answers: 99

Location: Mali
Member since Thu, Jul 9, 2020
4 Years ago
;