Log in

View Full Version : reading JS from a file with CSS



bglad
06-20-2006, 01:08 PM
Hi, I would liek to pull a js that I found on this forum from a file
<script type="text/javascript" src="js/dropmenu3.js"></script>
However, this script that I found on teh net has a CSS before the actual script starts. Now, can i just save the entire code in a .js file or does the <style> part have to be outside. If it's outside the file, how does the file refer to the CSS.

<style type="text/css">
#dropmenudiv{position:absolute;
border:1px #5559FB;
border-bottom-width: 0;
font:normal 12px Verdana;
line-height:18px;
z-index:100;
}
#dropmenudiv a{
width: 100%;
display: block;
text-indent: 20px;
border-bottom: 1px solid black;
padding: 1px 0;
text-decoration: none;
font-weight: bold;
color: white;
}
#dropmenudiv a:hover{ /*hover background color*/
background-color: #8080FF;
}
</style>

<script type="text/javascript">
//Contents for menu 1
var menu1=new Array()
menu1[0]='<a href="blah.php">- blah</a>'
menu1[1]='<a href="blah2.php">- blah2</a>'
...
</script>

Thanks for help
B

jscheuer1
06-25-2006, 05:38 AM
As long as the style is on or associated with the page, the script will use it. You could make the style external, not by putting it in the external script file but, by making it an external stylesheet. Save this to a file, call it dropmenu3.css:


#dropmenudiv {
position:absolute;
border:1px #5559FB;
border-bottom-width: 0;
font:normal 12px Verdana;
line-height:18px;
z-index:100;
}
#dropmenudiv a {
width: 100%;
display: block;
text-indent: 20px;
border-bottom: 1px solid black;
padding: 1px 0;
text-decoration: none;
font-weight: bold;
color: white;
}
#dropmenudiv a:hover { /*hover background color*/
background-color: #8080FF;
}

Then use like so:


<link rel="stylesheet" type="text/css" href="dropmenu3.css">
<script type="text/javascript" src="js/dropmenu3.js"></script>