Reputation: 496
Trying to hide a div based on another div
<script>
$(document).ready(function() {(
if($("p").hasClass('.out-of-stock')) {
$('#enquiry').hide();
}
});
</script>
however it is not working it doesn't hide
Live site at - http://trent-art.co.uk/shop/william-atherton-christmas-around-the-corner/
Trying to hide the submit best offer button if the item is out of stock.
Upvotes: 0
Views: 218
Reputation: 496
<script>
jQuery(document).ready(function($) {
if($('#foamy').hasClass('out-of-stock')) {
$('#enquiry').hide();
}
});
</script>
gave the p an ID!
Upvotes: 0
Reputation: 458
First of all, remove the "." in the .hasClass() method.
Second: Have you try with replace .is('.out-of-stock') instead .hadClass('.out-of-stock)?
Third: Do you want that the .hide() actions runs just on the DOM ready?
You code simply run at the document ready than stop. When the document is ready, the script check if your <p>
tag has the class "out-of-stock" and after this, it never look again it.
If you want that the check on the class is always running, you need to play with events, so .trigger() and .on().
Upvotes: 1