Adjusting the text size of an HTML element using JavaScript

Posted by

Changing Font Size with JavaScript

Changing Font Size with JavaScript

Click the buttons below to change the font size of this text.


function increaseFontSize() {
var text = document.getElementById(“text”);
var currentSize = window.getComputedStyle(text, null).getPropertyValue(‘font-size’);
var newSize = parseInt(currentSize) + 2;
text.style.fontSize = newSize + “px”;
}

function decreaseFontSize() {
var text = document.getElementById(“text”);
var currentSize = window.getComputedStyle(text, null).getPropertyValue(‘font-size’);
var newSize = parseInt(currentSize) – 2;
text.style.fontSize = newSize + “px”;
}

0 0 votes
Article Rating

Leave a Reply

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x