I didn’t look at your page that closely, but here’s the basic rule. If it’s JavaScript, and it’s supposed to alter elements in the HTML, then you have to do one of two things to ensure that the JavaScript has access to the DOM (document object model).
- Put the script block after the element(s) that you are trying to affect.
- Wrap the script in an unobtrusive “listener” function that will wait until the DOM is stabilized before running the code inside it.
For example:
<div id="foo">Some text</div>
<script type="text/javascript">
document.getElementById('foo').style.color = 'green';
</script>
That will work, because #foo exists at the time that the script runs (which is the instant that the browser encounters it in the flow of code). If the script tag was just above the div, then it wouldn’t work (you’d get an error that you couldn’t change the style on null or undefined).
For the second example, I have to rely on Prototype, cause I don’t remember the syntax off-hand to do a listener for the dom ready event.
<script src="path/to/prototype.js"></script>
<script type="text/javascript">
document.observe('dom:loaded', function(){
$('foo').setStyle('color:green');
});
</script>
</head>
<body>
<div id="foo">Some text</div>
The document.observe construction here is creating an event listener function in JavaScript, which waits until the browser signals the all-clear – that all of the DOM described in the source is loaded into memory and ready to accept modification. Depending on the complexity of your page, this may be quite a while after things start to “paint” to the screen.
Walter
On May 15, 2013, at 9:57 AM, RavenManiac wrote:
On 15 May 2013, 12:12 pm, The Big Erns wrote:
By the way, you’ve inadvertently put some CSS for the “Menu drop shadow” in
an inconvenient Page Markup position – Before instead of Before
… you should also probably fix that. Also, there are other notes
I’ve made in my markup of your page that I think will help better center
your table.
Ernie, I got it to work, but the ONLY way I was able to do so was to put the drop down menu code and the table code in the Before section. It wouldn’t work in the <Before area.
Should I put all of my drop down code in the Before section?
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options