Last active
December 13, 2017 09:42
-
-
Save ScarletPonytail/34f435cf092ad5374c437d4d582085c2 to your computer and use it in GitHub Desktop.
JS - Check is the div is empty and apply a class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Add the following comment code so you can indent the code and it still shows as empty --> | |
<div class="row"> | |
<div id="global-message-inner" class="col-md-12"><!-- | |
--><?php echo $this->getChildHtml('global_messages') ?><!-- | |
--></div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hide Global Message | |
$j(document).ready(function() { | |
var gmw = document.getElementById("global-message-wrapper"); | |
console.log('Hide message function is running'); | |
if ($j('#global-message-inner').is(':empty')) { | |
gmw.className += " hide-message"; // Teal | |
console.log('The empty class is being added'); | |
} | |
else { | |
gmw.className += " unhide-message"; // Purple | |
console.log('The filled class is being added'); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#global-message-wrapper { | |
color: #ffffff; | |
min-height: 40px; | |
line-height: 40px; | |
text-align: center; | |
margin-bottom: 60px; | |
} | |
.hide-message { | |
background-color: teal !important; | |
} | |
.unhide-message { | |
background-color: purple !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment