I am trying to change global variable finish from false to true using click event in order to prevent hovering the circles.
After I use click event, my global variable finish did not change (it is still false) and I can still do hovering over some circles.
Why is that happening?
var finish = false;
$( ".rating-circle" ).click( function() {
$( this ).addClass( "rating-chosen" );
$( this ).prevAll().addClass( "rating-chosen" );
finish = true;
});
if ( finish == false )
{
$( ".rating-circle" ).hover(
function() {
$( this ).addClass( "rating-hover" );
$( this ).prevAll().addClass( "rating-hover" );
},
function() {
$( this ).removeClass( "rating-hover" )
$( this ).prevAll().removeClass( "rating-hover" );
} );
}
body {
font-family: Verdana;
}
h1, h2, h3 {
color: darkblue;
}
.rating-circle {
height: 2em;
width: 2em;
border: .1em solid black;
border-radius: 1.1em;
display: inline-block;
margin: 0;
padding: .1em;
}
.rating-hover {
background-color: yellow;
}
.rating-chosen {
background-color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>Finding elements using jQuery</h2>
<h3>Rate this session</h3>
<div id="rating-container">
<div class="rating-circle"></div>
<div class="rating-circle"></div>
<div class="rating-circle"></div>
<div class="rating-circle"></div>
<div class="rating-circle"></div>
</div>