Hey there!
I'm having trouble with this jQuery code that is supposed to fade in or fade out a div based on its contents.
Here is the HTML code:
<div class="mainContentWrapper">
sample text
</div>
And here is the CSS code:
div.mainContentWrapper{
display: none;
width: 80%;
margin: 0.5% 10%;
padding: 0.5% 3%;
box-sizing: border-box;
border-radius: 4px;
border: 0.15em solid #1C86EE;
background-color: rgba(255,255,255,0.65);
}
Lastly, the jQuery function I've been trying to use:
$(document).ready(function(){
$('.mainContentWrapper').on('change',function(){
var mainContentWrapper_str=$.trim($(this).text());
if(mainContentWrapper_str.length==0){
$('.mainContentWrapper').fadeOut(500);
}else{
$('.mainContentWrapper').fadeIn(500);
}
});
});