jQuery Style How to - Get value of inline style








Question

We would like to know how to get value of inline style.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--   w w  w  . j  a v  a2 s.c  o  m-->
    $(function() {
      console.log($(".testclass").css("margin-top"));
      console.log(parseInt($(".testclass").css("margin-top")));
    });
});
</script>
</head>
<body>
  <div class="testclass"
    style="margin-top: 30px; width: 200px; height: 200px; border: 1px solid #000;"></div>
</body>
</html>

The code above is rendered as follows: