0
   

Javascript onclick change fontsize

 
 
Reply Fri 5 Jun, 2015 02:10 am
Hi everyone, I've got a problem with changing the font-size. I've tried a few methods like this :

function resizeText(multiplier) {
if (document.body.style.fontSize == "") {
document.body.style.fontSize = "1.0em";
}
document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
}
but it didn't work because I'm working on a website that's been made by professionnals and they didn't use em but the values xx-small, small, large... so I started doing strange stuff like this :

function resizeText(multiplier){

var tab = ["xx-small", "x-small", "small", "medium", "large"," x-large", "xx-large"];

if (document.body.style.fontSize == "") {

switch(tab){
case 'xx-small':
document.body.style.fontSize = "x-small";
break;
case 'x-small':
document.body.style.fontSize = "small";
break;

and so on...

}
}

The only thing that worked in my switch was the default value I put to the font-size.

Then I don't think that putting an array inside a switch is a good idea, I've been thinking about looping or using if/else but somehow I just can't find the answer. I keep doing strange stuff. So if someone could guide me in the right direction, I'dd be gratefull.
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 936 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Javascript onclick change fontsize
Copyright © 2025 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 02/05/2025 at 02:52:02