JavaScript Clear Inline Style of Paragraph

To clear Inline Style of a paragraph using JavaScript, get the reference to the paragraph element, and assign empty string value to the element.style property.

Note: This solution clears only the inline style. Any global styles using style sheets shall be applied to the element.

Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head> 
<body>
    <p id="myPara" style="color:red;width:200px;border:1px solid green">Clear Inline Style Paragraph in JavaScript</p>
    <button type="button" onclick="changeStyle()">Click Me</button>
    <script>
    function changeStyle(){
        var element = document.getElementById("myPara");
        element.style = "";
    }
    </script>
</body>
</html>

Conclusion

In this JavaScript Tutorial, we learned how to clear inline style of a paragraph using JavaScript.