JavaScript – Change Paragraph Text to Italic
To change paragraph text to italic using JavaScript, get the reference to the paragraph element, and assign element.style.fontStyle
property with value of "italic"
.
Example
</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<p id="myPara">Change Text in Paragraph to Italic using JavaScript</p>
<button type="button" onclick="changeStyle()">Click Me</button>
<script>
function changeStyle(){
var element = document.getElementById("myPara");
element.style.fontStyle = "italic";
}
</script>
</body>
</html>
Conclusion
In this JavaScript Tutorial, we learned how to change text in a paragraph to italic using JavaScript.