Run

Tutorial With Example

Run your live code

 
21
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
    <meta charset="utf-8">
5
    <title>JS Get Element's Style Demo</title>
6
</head>
7
<body>
8
    <p id="intro" style="color:red; font-size:20px;">This is a paragraph.</p>
9
    <p>This is another paragraph.</p>
10
        
11
    <script>
12
    // Selecting element
13
    var elem = document.getElementById("intro");
14
     
15
    // Getting style information from element
16
    alert(elem.style.color);  // Outputs: red
17
    alert(elem.style.fontSize);  // Outputs: 20px
18
    alert(elem.style.fontStyle);  // Outputs nothing
19
    </script>
20
</body>
21
</html>