javascript - Query if else if else check true? -
hello want check if div has class active. first item works, after stops. can tell me how fix this? (its slider, has work not on click.) slides automatic. http://i61.tinypic.com/28h2zb6.jpg
<script> $(document).ready(function () { if ($('#211').hasclass('item active')){ $('.vandaag').css("background-color", "blue"); console.log("werkt1!");} else if ($('#218').hasclass('item active')){ $('.vandaag').css("background-color", "#005993"); console.log("werkt2!");} else if ($('#219').hasclass('active')){ $('.vandaag').css("background-color", "#005993"); console.log("werkt3!");} }); </script>
the number id of image slider. , .item .active when slide active. greetz
don't use else if
, because stops after first block works.
instead use if() { }
blocks.
$(document).ready(function() { if ($('#211').hasclass('item active')) { $('.vandaag').css("background-color", "blue"); console.log("works!"); } if ($('#218').hasclass('item active')) { $('.vandaag').css("background-color", "#005993"); console.log("works2!"); } if ($('#219').hasclass('active')) { $('.vandaag').css("background-color", "#005993"); console.log("works3!"); } });
Comments
Post a Comment