Jump to content

Using DHTML to change appearance


RayT
 Share

Recommended Posts

Working from 'JavaScript for Dummies' I have modified the listing 4-5 to change the font-sizes of a large page of text to small, medium and large. It works well but uses several lines of <script>.....</script> within the header:function changeTheme() { switch(document.myForm.themes.selectedIndex) { case 0: document.getElementById("graf1").style.fontSize="small"; break; case 1: document.getElementById("graf1").style.fontSize="medium"; break; case 2: document.getElementById("graf1").style.fontSize="large"; break; }}Question: can I safely embed this routine within my CSS file? - and if so how? please.

Link to comment
Share on other sites

Can you put javascript in css? noyou could put the javascript in an external script file.

Thanks, but I've trawled the websites and textbooks but cannot find what an external script file looks like! Does it have HTML headers etc?I've tried saving raw javascript code as a .js file and calling from the web page but with no functionality!RayT
Link to comment
Share on other sites

ok, take everything that is inside the <script> tags and put it in another file named somefile.js . then in you page where the script used to be put this:

<script type="text/javascript" src="somefile.js"></script>

LG

Link to comment
Share on other sites

ok, take everything that is inside the <script> tags and put it in another file named somefile.js .  then in you page where the script used to be put this:
<script type="text/javascript" src="somefile.js"></script>

LG

Bingo! Works perfectly. Help much appreciated - obvious once you know!RayT
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
 Share

×
×
  • Create New...