Home >Web Front-end >JS Tutorial >How to change font size in javascript
How to change the font size in JavaScript: First create an HTML sample file; then define some text content; and finally change the font size through "ps[i].style.fontSize="12px";".
The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer
How to change the font size in javascript?
is very simple, the code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script language=javascript> window.onload=function(){ var ps=document.getElementById('neirong').getElementsByTagName('span'); for(var i=0;i<ps.length;i++){ ps[i].style.fontSize="12px"; } } </script> </HEAD> <BODY> <div id="neirong"> <p style="line-height: 30pt; text-indent: 32pt;"> <span style="font-size:16px;"> 谢谢! </span> </P> <p style="line-height: 30pt; text-indent: 32pt;"> <span style="font-size:16px;"> 谢谢! </span> </P> <p style="line-height: 30pt; text-indent: 32pt;"> <span style="font-size:16px;"> 谢谢! </span> </P> </div> </BODY> </HTML>
Recommended learning: "javascript Advanced Tutorial"
The above is the detailed content of How to change font size in javascript. For more information, please follow other related articles on the PHP Chinese website!