JQuery computes CSS value

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 } 
+4
source share
3 answers

Try the following:

 $marginTop = $('.emp-wrap').css("margin-top"); 
+5
source
 $marginTop = $('.emp-wrap').css("margin-top"); 
+1
source

use the following

 $('.emp-wrap').css("margin-top"); 

Alternatively, you can use parseInt to get only an integer value

 parseInt($(".testclass").css("margin-top")); 

See: http://jsfiddle.net/kEVq7/

0
source

All Articles