I am trying to increase the fonts size of my page using javascript. I have this code but it is not working as expected. Can someone please check what I am not doing correctly?
here is the HTML and javascript code:
<body>
<center>
<button type="button"
onclick="changeSizeByBtn(15)" name="btn1">
-A
</button>
<button type="button"
onclick="changeSizeByBtn(20)" name="btn2">
A
</button>
<button type="button" onclick="changeSizeByBtn(25)"
name="btn3">
A+
</button>
<br /><br />
<div style="padding: 20px; margin: 50px;
font-size: 20px; border: 5px solid red;"
id="container" class="container">
<p>
I need to increase this texts here by clicking on A+ button and decrease them by clicking -A button above.<br>
Or increase and decrease them by draging the range below to left or right<br> What is wrong in my code?
</p>
</div>
<input type="range" min="10" max="100" id="slider"
onchange="changeSizeBySlider()" value="40" />
</center>
<script>
var cont = document.getElementById("container");
function changeSizeByBtn(size) {
// Set value of the parameter as fontSize
cont.style.fontSize = size;
}
function changeSizeBySlider() {
var slider = document.getElementById("slider");
// Set slider value as fontSize
cont.style.fontSize = slider.value;
}
</script>