I want to stop setInterval() when left margin is 1200px. My code is :-
<html>
<body>
<script src="jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function () {
$('#btn').click(function () {
var i = setInterval(function () {
$('img').animate({
'margin-left': '+=100px'
}, 'fast');
var a = $('img').css('margin-left');
if (a == "1200px") {
clearInterval(i);
}
}, 50);
});
});
</script>
<img src="48_800[1].jpg" height="50px" width="50px"><br>
<input type="button" value="start" id="btn"><br>
</body>
</html>
It is not working.Can anyone help me?