473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can i reference CSS file in my JavaScript File ".js"

Hello Friends,
The JavaScript File exmplmenu_var.js contains the code... (for the
sake of brevity i am showing only that code which needs to be changed)

I am actually developing a menu using JavaScript. I have used a
readymade javascript and there are variables like...
var LowBgColor='#0c4297'; // Background color when mouse is not over
var LowSubBgColor='#0c4297'; // Background color when mouse is not
over on subs
var HighBgColor='0c4297'; // Background color when mouse is over
var HighSubBgColor='#0e1651'; // Background color when mouse is over
on subs
var FontLowColor='white'; // Font color when mouse is not over
var FontSubLowColor='white'; // Font color subs when mouse is not
over
var FontFamily="Abadi MT Condensed" // Font family menu items

My Question is simple, instead of putting the values in JavaScript
File, for color, font, etc. i want to use the .css file, for e.g.
classname instead of values like '#0c4297'.

Any help?

Regards,
Mahernoz

Sep 27 '07 #1
9 2877
"Mahernoz" <ma******@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
>
My Question is simple, instead of putting the values in JavaScript
File, for color, font, etc. i want to use the .css file, for e.g.
classname instead of values like '#0c4297'.
Create a CSS class for each colourway and use javascript to change the class
of the element.

Steve.
Sep 27 '07 #2
On Sep 27, 3:23 pm, "Steve Robinson"
<stephen.p.robinson.butnotthis...@ntlworld.comwrot e:
"Mahernoz" <maher...@gmail.comwrote in message

news:11**********************@57g2000hsv.googlegro ups.com...
My Question is simple, instead of putting the values in JavaScript
File, for color, font, etc. i want to use the .css file, for e.g.
classname instead of values like '#0c4297'.

Create a CSS class for each colourway and use javascript to change the class
of the element.

Steve.
Yes i want to accomplish that only, please give the code as how to
change the class of the element using JavaScript. Can i call the CSS
in my .js file with the <linktag?
Sep 27 '07 #3
"Mahernoz" <ma******@gmail.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
>
Yes i want to accomplish that only, please give the code as how to
change the class of the element using JavaScript. Can i call the CSS
in my .js file with the <linktag?
Actually a better solution might be not to use javascript at all and use the
pseudo-class hover to change the colour of the element when the mouse is
over it.
http://www.w3schools.com/css/pr_pseudo_hover.asp

Steve.

Sep 27 '07 #4
On Sep 27, 3:32 pm, "Steve Robinson"
<stephen.p.robinson.butnotthis...@ntlworld.comwrot e:
"Mahernoz" <maher...@gmail.comwrote in message

news:11**********************@r29g2000hsg.googlegr oups.com...
Yes i want to accomplish that only, please give the code as how to
change the class of the element using JavaScript. Can i call the CSS
in my .js file with the <linktag?

Actually a better solution might be not to use javascript at all and use the
pseudo-class hover to change the colour of the element when the mouse is
over it.http://www.w3schools.com/css/pr_pseudo_hover.asp

Steve.
Hi Steve,

if i use this pseudo-class hoverinstead of javascript menus. How will
i be able to make menus? would a normal html table be enough to make a
menu? because this menu (in the .js file) has N Level hierarchy. How
can i use css, to make such N-Level menus without using JavaScript?

- Mahernoz

Sep 27 '07 #5
"Mahernoz" <ma******@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...
>
if i use this pseudo-class hoverinstead of javascript menus. How will
i be able to make menus? would a normal html table be enough to make a
menu? because this menu (in the .js file) has N Level hierarchy. How
can i use css, to make such N-Level menus without using JavaScript?
You don't use CSS to make the menus, only to style them.

I find that nested lists are the best way to generate hierarchical menus.
They can be any number of levels deep but usability suffers if they are more
than 3 or 4 levels and in that case you might want to review your
information architecture.

Steve.
Sep 27 '07 #6
On Sep 27, 4:32 pm, "Steve Robinson"
<stephen.p.robinson.butnotthis...@ntlworld.comwrot e:
"Mahernoz" <maher...@gmail.comwrote in message

news:11*********************@w3g2000hsg.googlegrou ps.com...
if i use this pseudo-class hoverinstead of javascript menus. How will
i be able to make menus? would a normal html table be enough to make a
menu? because this menu (in the .js file) has N Level hierarchy. How
can i use css, to make such N-Level menus without using JavaScript?

You don't use CSS to make the menus, only to style them.

I find that nested lists are the best way to generate hierarchical menus.
They can be any number of levels deep but usability suffers if they are more
than 3 or 4 levels and in that case you might want to review your
information architecture.

Steve.
Hi Steve,
Thanks, i will try to implement CSS Menus from
http://meyerweb.com/eric/css/edge/menus/demo.html. I hope this solves.
Regards,
Mahernoz

Sep 27 '07 #7
On Sep 27, 5:27 am, Mahernoz <maher...@gmail.comwrote:
On Sep 27, 4:32 pm, "Steve Robinson"

<stephen.p.robinson.butnotthis...@ntlworld.comwrot e:
"Mahernoz" <maher...@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...
if i use this pseudo-class hoverinstead of javascript menus. How will
i be able to make menus? would a normal html table be enough to make a
menu? because this menu (in the .js file) has N Level hierarchy. How
can i use css, to make such N-Level menus without using JavaScript?
You don't use CSS to make the menus, only to style them.
I find that nested lists are the best way to generate hierarchical menus.
They can be any number of levels deep but usability suffers if they are more
than 3 or 4 levels and in that case you might want to review your
information architecture.
Steve.

Hi Steve,
Thanks, i will try to implement CSS Menus fromhttp://meyerweb.com/eric/css/edge/menus/demo.html. I hope this solves.
Regards,
Mahernoz
Keep in mind, though, that Internet Explorer 5-6 only supports
the :hover pseudoclass on <aelements, so if you want your menu to
work in IE6, you'll have to use at least SOME JavaScript. However,
you may try making a CSS-only menu system, like Steve suggests, for
all other modern browsers, only implementing the JS fallback for IE6.
Or you may find that supporting different code for different browsers
is too much hassle, and go with JavaScript menus that degrade well in
browsers without JavaScript. CSS-only dropdowns were very promising
ca. 2003, but continuing lack of pseudoclass support has meant that
they're seldom used in practice.

Still, you're correct that it's irresponsible for a JS script to be
specifying colors like that. That's the job of a CSS file. Use the
string property element.className to set CSS classes on an element
instead.

-David

Sep 27 '07 #8
On Sep 27, 8:31 pm, David Golightly <davig...@gmail.comwrote:
On Sep 27, 5:27 am, Mahernoz <maher...@gmail.comwrote:
On Sep 27, 4:32 pm, "Steve Robinson"
<stephen.p.robinson.butnotthis...@ntlworld.comwrot e:
"Mahernoz" <maher...@gmail.comwrote in message
>news:11*********************@w3g2000hsg.googlegro ups.com...
if i use this pseudo-class hoverinstead of javascript menus. How will
i be able to make menus? would a normal html table be enough to make a
menu? because this menu (in the .js file) has N Level hierarchy. How
can i use css, to make such N-Level menus without using JavaScript?
You don't use CSS to make the menus, only to style them.
I find that nested lists are the best way to generate hierarchical menus.
They can be any number of levels deep but usability suffers if they are more
than 3 or 4 levels and in that case you might want to review your
information architecture.
Steve.
Hi Steve,
Thanks, i will try to implement CSS Menus fromhttp://meyerweb.com/eric/css/edge/menus/demo.html. I hope this solves.
Regards,
Mahernoz

Keep in mind, though, that Internet Explorer 5-6 only supports
the :hover pseudoclass on <aelements, so if you want your menu to
work in IE6, you'll have to use at least SOME JavaScript. However,
you may try making a CSS-only menu system, like Steve suggests, for
all other modern browsers, only implementing the JS fallback for IE6.
Or you may find that supporting different code for different browsers
is too much hassle, and go with JavaScript menus that degrade well in
browsers without JavaScript. CSS-only dropdowns were very promising
ca. 2003, but continuing lack of pseudoclass support has meant that
they're seldom used in practice.

Still, you're correct that it's irresponsible for a JS script to be
specifying colors like that. That's the job of a CSS file. Use the
string property element.className to set CSS classes on an element
instead.

-David
Hi David,

Thanks for a timely advice, yes, the above menu doesn't work in IE6
(unfortunately, this i discovered much later).
The problem is the elements(menuitems) are contructed at runtime, so i
need to get the classname in
my .js file (the javascript file which generates the menu). Any idea?

I am using the javascript menu from burmees.nl which supports both ie6
and firefox and also images and text, but the only
thing that i am not having is css support. Otherwise, it's quite easy
to setup(this is required because the client wants to maintain the
menus)

Any alternative in your mind?
Please help.

Regards,
Mahernoz

Sep 28 '07 #9
On Sep 28, 4:08 pm, Mahernoz <maher...@gmail.comwrote:
On Sep 27, 8:31 pm, David Golightly <davig...@gmail.comwrote:
On Sep 27, 5:27 am,Mahernoz<maher...@gmail.comwrote:
On Sep 27, 4:32 pm, "Steve Robinson"
<stephen.p.robinson.butnotthis...@ntlworld.comwrot e:
"Mahernoz" <maher...@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...
if i use this pseudo-class hoverinstead of javascript menus. How will
i be able to make menus? would a normal html table be enough to make a
menu? because this menu (in the .js file) has N Level hierarchy. How
can i use css, to make such N-Level menus without using JavaScript?
You don't use CSS to make the menus, only to style them.
I find that nested lists are the best way to generate hierarchical menus.
They can be any number of levels deep but usability suffers if they are more
than 3 or 4 levels and in that case you might want to review your
information architecture.
Steve.
Hi Steve,
Thanks, i will try to implement CSS Menus fromhttp://meyerweb.com/eric/css/edge/menus/demo.html. I hope this solves.
Regards,
>Mahernoz
Keep in mind, though, that Internet Explorer 5-6 only supports
the :hover pseudoclass on <aelements, so if you want your menu to
work in IE6, you'll have to use at least SOME JavaScript. However,
you may try making a CSS-only menu system, like Steve suggests, for
all other modern browsers, only implementing the JS fallback for IE6.
Or you may find that supporting different code for different browsers
is too much hassle, and go with JavaScript menus that degrade well in
browsers without JavaScript. CSS-only dropdowns were very promising
ca. 2003, but continuing lack of pseudoclass support has meant that
they're seldom used in practice.
Still, you're correct that it's irresponsible for a JS script to be
specifying colors like that. That's the job of a CSS file. Use the
string property element.className to set CSS classes on an element
instead.
-David

Hi David,

Thanks for a timely advice, yes, the above menu doesn't work in IE6
(unfortunately, this i discovered much later).
The problem is the elements(menuitems) are contructed at runtime, so i
need to get the classname in
my .js file (the javascript file which generates the menu). Any idea?

I am using the javascript menu from burmees.nl which supports both ie6
and firefox and also images and text, but the only
thing that i am not having is css support. Otherwise, it's quite easy
to setup(this is required because the client wants to maintain the
menus)

Any alternative in your mind?
Please help.

Regards,Mahernoz
Hi David,
Instead of this in my Js(JavaScript) file...

var LowBgColor='#0c4297'; // Background color when mouse is not over
var LowSubBgColor='#0c4297'; // Background color when mouse is not
over on subs
var HighBgColor='#0c4297';

can i have this...

var LowBgColor=ClassName; // Background color when mouse is not over
var LowSubBgColor=ClassName; // Background color when mouse is not
over on subs
var HighBgColor=ClassName;

this will shorten my work drastically.

Regards,
Mahernoz

Sep 28 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: mike | last post by:
regards: I use Jtidy (api) to translate a HTML file into a "XHTML file". But The "XHTML file" cannot be identified by nokia 6600. Do I miss something important? Or this is Jtidy's weakness or...
25
by: delerious | last post by:
I see some code examples like this: <DIV onmouseover="this.style.background='blue'"> and other code examples like this: <DIV onmouseover="javascript:this.style.background='blue'"> Which...
9
by: David D. | last post by:
Does the file extension matter when including a JavaScript file in an HTML page? Normally, one would include a JavaScript file in an HTML page using <script src="foo.JS" type="text/javascript">...
10
by: Blue® | last post by:
I would like to call the content of content.htm (containing only HTML codes) into index.htm. This is usually done by renaming index.htm to index.shtml and use this tag: <!--#include...
7
by: RFS666 | last post by:
Hello, I would like to use variables with a type in jscript.NET. I declare them as follows: var x : double = 5.03; This doesn't work in my script, that I write to the page in codebehind with...
1
by: Slavo Smutny | last post by:
Hi, which is better approach to store my JavaScript code, to store it in separate .js file or to embed the code within HTML attributes (e.g. <p onclick="javascript:submit();">click this</p>)? I...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
3
by: joe | last post by:
Is it OK to have multiple: <script type="text/javascript" src="funcs1.js"></script> <script type="text/javascript" src="funcs2.js"></script> <script type="text/javascript"...
6
by: passionateforjava | last post by:
Hi All, I am using struts application wherein I need to import file for some purpose.I have used input type="file" for the same which goes like: <input type="file" id="uploadFile" name="uploadFile"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.