I have a loop that reduces margin-top by 182px in each iteration. I want to get the margin-top value, so I can tell when to stop, but when I try to run it in the console, it will return "undefined". Please advise how to change this to get the real value.
This is what I use, I use attr () because the value it needs to get is its inline style:
$marginTop = $('.emp-wrap').attr("style");
Rest of code below
// if statements to move carousel up $carouselNum = $('.carousella').length; $marginTop = $('.emp-wrap').attr("style"); if($carouselNum > 1){ // // function empMove, the '-=' allows the -margin-top to run every time. Without this it will set the margin-top to the same value every loop function empMove() { $('.emp-wrap').css('margin-top', '-=182')}; setInterval(empMove, 20000); } else if($carousel < 1){ // do something } else{ // do something }
source share