Jump to content

Changing the font family of all objects in a doc


aleksanteri

Recommended Posts

I have been thinking about a way to change the font family for all elements in a document with JavaScript/DOM?I have tried it with a onerror script but it doesn't help me this time.

function newfont(){	document.all.style.fontFamily=document.getElementByName("NewFont").value}

Plz help

Link to comment
Share on other sites

<script>function newfont(){document.body.style.fontFamily=document.getElementsByName("NewFont")[0].value}</script>
Remember fetching elements by name returns an array, so there should be an S in the middle, and you should define the element of the array (which of the elements that has that name attribute) additionally. Last, document.all is rarely supported nowdays, you should forget those (its about layers), instead, you could use the body as the element onwhich the style is applied. :)(or easily add a statement by using CSS, instead of JavaScript, CSS was meant to do like this and JavaScript don't) Edited by Dan The Prof
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...