Reputation: 39
Good evening!
I have the following code in jQuery that doesnt work. The idea of the code is to fade in or fade out the div depending on the contents.
html code:
<div class="mainContentWrapper">
sample text
</div>
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);
}
jquery function:
$(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);
}
});
});
Upvotes: 0
Views: 62
Reputation: 168
onChange can only be used with <input>
, <select>
and <textarea>
.
Upvotes: 1
Reputation: 353
onChange
dosen't apply to changes to the css. It is meant for user interface elements such as <input>
or <textarea>
.
Upvotes: 3