Jump to content
  • Advertisement
Sign in to follow this  
onceloving

[web] Changing font in a function

This topic is 5063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having trouble and I don't really know where to go from here.
<html>
<head>
</head>
<script>
function changefont() {
document.body.style.font-family="arial"}
</script>
<body>
Hi
<form>
<input type="button"
onclick="changefont()"
value="Arial">
</form>
</body>
</html>


Share this post


Link to post
Share on other sites
Advertisement
In javascript, the style attributes are changed slightly to remove special characters such as hypens. In javascript, the term document.body.style.font-family will be handled as two variables, with the RHS being subtracted from the LHS - in this case the 'variable' family is being subtracted from the font attribute of document.body.style. You'll get a JS error because the interpreter can't find the variable family.

To remove these problems, you should refer to a resource such as the one here and select the correct style attribute, in your case you're looking for style.fontFamily


<html>
<head>
</head>
<script>
function changefont() {
document.body.style.fontFamily="arial"}
</script>
<body>
Hi
<form>
<input type="button" onclick="changefont()" value="Arial">
</form>
</body>
</html>




With this simple change the code you specified works.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!