Home  >  Article  >  Web Front-end  >  How to change font size in javascript

How to change font size in javascript

藏色散人
藏色散人Original
2021-07-01 10:32:375008browse

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";".

How to change font size in javascript

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(&#39;neirong&#39;).getElementsByTagName(&#39;span&#39;);
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn