aleksanteri Posted May 19, 2006 Share Posted May 19, 2006 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 More sharing options...
Jack McKalling Posted May 19, 2006 Share Posted May 19, 2006 (edited) <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 May 19, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
aleksanteri Posted May 19, 2006 Author Share Posted May 19, 2006 I tried switching the "all" to "body" but it didn't work (not if I had thought the problem was at the left side, not at the right side) thanx Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 19, 2006 Share Posted May 19, 2006 Doesn't it work right now? Could you give me a link so I can check it out myself? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now