DOM - what is it? A good idea?

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Re: DOM - what is it? A good idea?

Post by nathandelane on Wed Aug 06, 2008 3:25 pm
([msg=8970]see Re: DOM - what is it? A good idea?[/msg])

The tutorial you are viewing is a little bit outdated. But it is still mostly valid. The information, programming-wise that you are seeing has to do with JavaScript (which is in no way related to Java) also known as ECMAScript. As for Netscape, it is no longer being made, so anybody who uses Netscape as their browser to surf the Internet is at a loss. The main browsers you should worry about are Internet Explorer, Mozilla Firefox, and Apple Safari (most other browsers are based on these three, for example KDE's Konqueror in Linux is based on Safari). As for worrying about whether or not JavaScript works in the user's browser or is disabled, the best practice now is to enclose completely different web page source code inside of

Code: Select all
<noscript>
</noscript>


tags. The correct method of using the DOM in programming is to use constructive and destructive XML-based methods. This basically means that instead of document.write("<i>Hello World!</i>") you would use

Code: Select all
var el = document.createElement("i"); // Create a new i-element
// Add a text node containing the text 'Hello World!' to it
el.appendChild(document.createTextNode("Hello World!"));
document.body.appendChild(el); // Add the new i-element to the document body.
Me, Nathandelane, Highly influential to Hackerdom, Premature Optimization=http://c2.com/cgi/wiki?PrematureOptimization
User avatar
nathandelane
Poster
Poster
 
Posts: 204
Joined: Thu Jun 26, 2008 11:26 am
Location: Utah
Blog: View Blog (0)


Previous

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests