Is there a way to continuously check if an area has the class "top-nav" in order for the alerts to work every time it lacks or contains the class? How can I achieve this functionality?
Check out the code on jsfiddle: https://jsfiddle.net/jzhang172/117mg0y1/
if(!$('.view-projects').hasClass("top-nav")){
alert('has');
}else if($('.view-projects').hasClass("top-nav")){
alert('hey');
}
$('.push').click(function(){
$('.view-projects').toggleClass('top-nav');
});
.view-projects{
height:100px;
width:100%;
background:black;
}
body,html{
margin:0;
padding:0;
}
.push{
height:200px;
width:100px;
background:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="view-projects"></div>
<div class="push"></div>