I am trying to hide a div if a particular text is displayed in between. I am using jquery and this is the code:
HTML
<div class="deliveryUpsellText">
<p>blabla</p>
</div>
<ul>
<li class="error-msg">
<ul>
<li>
<span> Coupon Code "blabla" is not valid
</span>
</li>
</ul>
</li>
</ul>
<button type="button" id="cartCoupon" title="Apply Coupon" class="button applycouponhide" onclick="discountForm.submit(false) ; " value="Apply Coupon"><span style="background:none;"><span style="background:none;">Apply</span></span></button>
JQuery
$j('#cartCoupon').click(function(){
if($j(".error-msg span:contains('blabla')")){
$j('.deliveryUpsellText').css({"display":"none"});
}
});
It hides the div on a click, but it ignores the if statement. Therefore, even if the text in the span is "cat", it still hides the div. Can anyone understand what I did wrong? Just like a button #cartCouponhas an onclick event, the UpsellText dicountForm.submit(false);delivery is hidden when clicked, but does not bind to the submit form, so it displays again after the form is submitted. Does anyone know how I can fix this?
source
share