benjaminsv — 2012-04-15T10:59:42-04:00 — #1
the issue I am having is the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<p>Welcome to a site about making pizza</p>
<p>While pizza is delicious with the above ingredients, it is even better when you add toppings!</p>
This is what I have attempted to diagnose:
1. Embed js (I always use external files)
2. open html in Chrome, FF, IE
3. open html from local path and from my domain via its stage
4. empty browser's saved data (cookies, cache, history etc)
5. Ensure HTML markup is not impeding JS -> W3C XHTML valid
Its beyond me as to why such a simple and small amount of code could possibly fail. Thanks for reading and offering suggestions!
chris_upjohn — 2012-04-15T11:07:26-04:00 — #2
The problem is that your attempting to execute the code before the DOM (Document Object Model) is ready, to fix the issue you can do one of two things:
- Use the window.onload method which waits for the DOM to be ready before it executes the code
- Place the <script> tags before the closing </body> tag which will always wait until the DOM is ready
benjaminsv — 2012-04-15T11:15:18-04:00 — #3
That sounds great!
I'd rather not use window.onload for the same reason, always best to minimize code
I would prefer to use external than embedded code - are you suggesting the following...
2. <script src=".js"></script><body>
chris_upjohn — 2012-04-15T11:18:29-04:00 — #4
Basically with what your trying to do you would simply use something like the below.
var target = document.getElementById('tagline');
benjaminsv — 2012-04-15T11:30:24-04:00 — #5
That worked, thanks Chris.
chris_upjohn — 2012-04-15T11:53:56-04:00 — #6
Sent from my iPhone using Tapatalk