treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Font Size Changer

  • How can I make this code increase & Decrease multiple tags font sizes.. Basically. I want it to change the font size of EVERYTHING on the page, not just



    Help?

    var min=8;
    var max=18;
    function increaseFontSize() {
    var p = document.getElementsByTagName('p');
    for(i=0;i<p.length;i++) {
    if(p[i].style.fontSize) {
    var s = parseInt(p[i].style.fontSize.replace("px",""));
    } else {
    var s = 12;
    }
    if(s!=max) {
    s += 1;
    }
    p[i].style.fontSize = s+"px"
    }
    }
    function decreaseFontSize() {
    var p = document.getElementsByTagName('p');
    for(i=0;i<p.length;i++) {
    if(p[i].style.fontSize) {
    var s = parseInt(p[i].style.fontSize.replace("px",""));
    } else {
    var s = 12;
    }
    if(s!=min) {
    s -= 1;
    }
    p[i].style.fontSize = s+"px"
    }
    }
  • I imagine its something to do with the variables, but I've tried things and not working so good.
  • Hey Waffle, you ever thought about using jQuery? I don't really code in raw javascript but you could accomplish this quite easily using jQuery.
  • Oh right? I'll give it a gander