The following function will check every 1 second whether an element with the class elementClass
has a margin-left
set as 200px
. If so, an alert
will be triggered (as an example).
$(document).ready(function(){
setInterval(function(){
if ($(".elementClass").css("marginLeft")=='200px'){
//do something here
alert("margin is 200px");
}
}, 1000);
});
However, this code will then trigger the event every second that the margin-left
is 200px
. The following will only trigger the event the first time the element has been detected with the 200px margin-left:
var eventtrig = 0;
$(document).ready(function(){
setInterval(function(){
if ($(".elementClass").css("marginLeft")=='200px' && eventtrig=0) {
//do something here
alert("margin is 200px");
eventtrig=1;
}
else {
eventtrig=0;
}
}, 1000);
});