Js changes the text font size of the instance code

  • 2020-03-29 23:59:13
  • OfStack

When I first came to the company, the leader gave me some simple, simple and simple... task

Once asked me to write out the font size conversion function of the article. Searching a lot on the Internet doesn't work! But everything comes to him who waits. I found him! Share it!

<script type= " text/javascript " >
    Function SetFont(size){
        var divBody = document.getElementById( " news_content " );
  divBody.style.fontSize = size+ " px " ;
  Var divChildBody = divBody.childNodes;
  For (var i = 0; i<divChildBody.length;i++){
         divChildBody[i].style.fontSize=size+ " px " ;

HTML part

 The font size: <a href="javascript:SetFont(16)"> big </a> <a href="javascript:SetFont(14)"> In the </a> <a href="javascript:SetFont(12)"> small </a> 】 
      <div style="font-size:14px;" id="news_content">
        The article content 

Related articles: