Get css text for an element in JavaScript

Description

The following code shows how to get css text for an element.

Example


<!--   ww w .  ja  va  2 s .c  om-->

<html>
<body>
<P>Click on the square.</p>
<div id="div1"
style="background-color: red; height: 50px; width: 50px"
onclick="alert(this.style.cssText)"></div>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get css text for an element in JavaScript