jQuery Style How to - Get all CSS attributes








Question

We would like to know how to get all CSS attributes.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.4.3.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!-- w w w  . j  av a 2s  .com-->
   $(document).ready(function(){
      console.log($("#stylediv").attr('style'));
   });
});
</script>
</head>
<body>
  <div
    style="border: solid #000 2px; overflow: hidden; width: 250px; height: 10px"
    id="stylediv"></div>
</body>
</html>

The code above is rendered as follows: