jQuery Style How to - Read/get the CSS background color








Question

We would like to know how to read/get the CSS background color.

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 ww .j av  a  2s . c o  m-->
    console.log($('#div1')[0].style.backgroundColor);
});
</script>
</head>
<body>
  <div id="div1" style="background-color: red">asdf</div>
</body>
</html>

The code above is rendered as follows: