开发者

How to change FontSize By JavaScript?

This code is not working

var span = document.getElementById("span");
span.style.font开发者_如何转开发size = "25px";
span.innerHTML = "String";


JavaScript is case sensitive.

So, if you want to change the font size, you have to go:

span.style.fontSize = "25px";


<span id="span">HOI</span>
<script>
   var span = document.getElementById("span");
   console.log(span);

   span.style.fontSize = "25px";
   span.innerHTML = "String";
</script>

You have two errors in your code:

  1. document.getElementById - This retrieves the element with an Id that is "span", you did not specify an id on the span-element.

  2. Capitals in Javascript - Also you forgot the capital of Size.


try this:

var span = document.getElementById("span");
span.style.fontSize = "25px";
span.innerHTML = "String";


Please never do this in real projects

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜