Zarko Zivkovic Zarko Zivkovic - 1 year ago 56
Javascript Question

Change style of element when real time clock is under 15 minutes?

I want to change background of div when minutes on real time clock are less than 15. here is my code:

<script type="text/javascript">
window.setInterval(function(){
now = new Date;
c = now.getMinutes();
if (c < 15 ) {
$('#defaultCountdown').css('background': 'red');
}
}, 1000);

</script>


and here is link of page, where it is not going red, c < 50 is set:

http://signalsindicator.com/timer/index.html

Answer Source

Change

$('#defaultCountdown').css('background': 'red');

to

$('#defaultCountdown').css('background', 'red');

Or change it to

$('#defaultCountdown').css({
  'background': 'red'
});

window.setInterval(function(){
  now = new Date;
c = now.getMinutes();
if (c < 15 ) {
$('#defaultCountdown').css('background', 'red');
}
else{
 $('#defaultCountdown').css('background', 'blue'); 
}
}, 1000);
div{
  height:200px;
  width:200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="defaultCountdown"></div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download