I was wondering how you can resize text size in javascript based off of user input. Say for example, if the input exceeds 1000000000, then set text size to 14. The userinput in this case would be the Price and the size I would like to modify is the the TotalAmount and TipAmount.
-
element.style["font-size"] inside of a switch statementLuca Kiebel– Luca Kiebel2018-04-22 19:11:49 +00:00Commented Apr 22, 2018 at 19:11
-
I am not familiar with a switch statement but thank you for taking your time to respondJake Kovinsky– Jake Kovinsky2018-04-22 19:14:39 +00:00Commented Apr 22, 2018 at 19:14
-
2Please provide code of what you already tried and give a little more context.Philipp Meissner– Philipp Meissner2018-04-22 19:16:48 +00:00Commented Apr 22, 2018 at 19:16
Add a comment
|
3 Answers
Like this?
function changeTextSize() {
var input = document.getElementById('input').value;
document.getElementById('text').style.fontSize = input + "px";
}
<p id="text">I am some text.</p>
<input type="text" onkeyup="changeTextSize()" id="input">
Or like this?
function changeTextSize() {
var input = document.getElementById('input').value;
if (input > 1000) {
document.getElementById('text').style.fontSize = 30 + "px"; // Changed 14 to 30, because 14 would be smaller than the default text size
}
}
<p id="text">I am some Text</p>
<input type="text" onkeyup="changeTextSize()" id="input">
Comments
You may apply styles with JS.
Given that input and outputs are strings:
if(price > 10000){outputElement.style.fontSize = "0.8em"}
2 Comments
Luca Kiebel
14 is not a valid font-size value, developer.mozilla.org/en-US/docs/Web/CSS/font-sizeolaven
Updating now :-) Thanks!