View Full Version : changing CSS from within an external js-file

06-10-2004, 04:59 PM

I need to change a CSS-Style (background-Image) from within a JavaScript-File.
Normally I would use >> document.getElementById('headBox').style.backgroundImage='url(bg_pics/01.jpg)'; <<
But because t

06-11-2004, 08:59 PM
Looks like your message got cutoff there...


06-12-2004, 11:18 AM
oh no. f***!
okay, but the main information is there.
However: I'll try again:

I have a JS-function within a HTML-File, that changes the bg-Image of the headBox and I have a JS-Menu.
Now I want to have the bg-Image changed on every click in the menu.

Possibility (1): I find a way to speak to the headBox from the outer JS-File.
Possibility (2): I call up the function (that changes the bg-Image) in the HTML-File from somewhere else (maybe the easier way). From the Menu-JS-File or the linked HTML-File.

Hope this was understandable... :)

thanks a lot,

06-13-2004, 02:46 AM
Possibility 2 sounds good.

Unfortunately we couldn't help too much as we haven't seen the menu, the html, or any code really. Post some of that perhaps and we'll try and give you a hand.


06-13-2004, 11:44 AM
yeah. sure.
I got them in my opening post. Okay, here are some links:

To the testpage:
(in the header, there is the 'change_bgpic' function)
The CSS-File is called 'screen.css' and is located in the same directory.

I used a TopNav III * JS - Navigation Bar by Brothercake (http://www.brothercake.com/dropdown/topnavIII/custom.html)
To the menu:
(the Menu-Items are at the very bottom of the document)

The funcion shall now be loaded on every click on any nav-button or maybe it can be loaded with an onLoad-function from the linked file.

Hope this helps you to help me... :)
Thanks already!