0

I want to be able to get the font size to change when you click on the different sized letters that are on the right. How do I go about commanding the site to do that using javascript? Here is the code I have so far:

  <!DOCTYPE html>
<html>
<head>
<body>

<div> 
 <font size="2"><a href="javascript:void(0);" onclick="changemysize(16);">A</a></font>
 <font size="4"><a href="javascript:void(0);" onclick="changemysize(20);">A</a></font>
 <font size="5"><a href="javascript:void(0);" onclick="changemysize(25);">A</a></font>

</div>

<div id="callout" class="medium">
    <ul id="controls">
        <li id="small">A</li>
        <li id="medium">A</li>
        <li id="large">A</li>
    </ul>
    <div id="mymain">
         <h1>Header</h1>

         <h2>Subheader</h2>

        <p>Lorem ipsum dolor sit amet, pri ne periculis definiebas, habeo gloriatur has id. Ius ad ubique animal, eum recteque electram explicari no, sed in nostrum adipiscing. Lorem ipsum dolor sit amet, pri ne periculis definiebas, habeo gloriatur has id.</p>
    </div>
</div>
<p style="margin-top: 100px; text-align: center; font-size: 75%;"><a href="../resize.zip">Download the files (resize.zip)</a>

</p>

<script src="resize.js"></script> 

</body>
</head>
</html> 

Javascript:

function changemysize(myvalue) {
    var div = document.getElementById("mymain");
    div.style.fontSize = myvalue + "px";
}
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
user2916725
  • 1
  • 1
  • 2
  • 4

2 Answers2

0

Steps:

  • Define a class in your css file for enlarged fontsize.
  • Call a function on your li's onclick
  • Let the function add/remove respective class for ur html body document.body.classList.add('nameOfTheClassWithFontSize');

Ref: change text-font size of whole page content

Community
  • 1
  • 1
ajc
  • 1,685
  • 14
  • 34
  • Please try to follow the steps, use jsfiddle.net. If that dint help, please check the reference I shared. I'm sure you'll find your answer. – ajc Oct 31 '13 at 21:39
  • 1
    you are getting the element by document.getElementById("mymain"); But there isn't any html element with that id. – ajc Oct 31 '13 at 21:44
0

For your HTML using jQuery: $('body').css('font-size', '12px');

You can pass size you want for increasing/decreasing and so on.

comprex
  • 743
  • 3
  • 9
  • 20