Last updated on January 10th, 2023 at 02:03 pm
The font color, family and size of the text the id named p1 will be changed when user click the button. DOM(Document Object Model) is always useful for a web developer to dynamically change content inside a webpage. Here is a simple script that provide real time change of font size along with font family, size, style and color
<html>
<head>
<script>
function displayResult()
{
document.getElementById("p1").style.fontFamily="Helvetica";
document.getElementById("p1").style.fontStyle="oblique";
document.getElementById("p1").style.fontSize="xx-large";
document.getElementById("p1").style.color="Red";
}
</script>
</head>
<body>
<p id="p1">This text is going to change soon :-)</p>
<br>
<button type="button" onclick="displayResult()">Change Font Style, Family Color and Size</button>
</body>
</html>
We are using document.getElementById(“p1”).style to make these changes. I have created a function with all the details as shown above.
good tutorials i really love these simple yet good i am interested to put on my site