Introducing JavaScript

JavaScript has changed a great deal since it was first introduced but many sites still use outdated techniques. There are even lots of JavaScript tutorials on the web that show you how JavaScript should be written so that it can work in Netscape 2 rather than so that it will work in modern browsers. As a result there are many people who are writing what they think is JavaScript but where what they are producing is more suited to the 20th Century than to the 21st.

Beginners should work through all the basic examples prior to moving on to the other examples which cover separate aspects of JavaScript in more detail.

Most of the JavaScript examples here will work in IE5+, Opera7+ and all versions of Firefox, Safari and Chrome. Those commands introduced in ECMAScript5.1 in 2011 have been added (if I have missed any please let me know). Those commands introduced in ECMAScript2015 are currently being added (there are lots of them so it may take some time but then most current browsers do not yet support them all anyway). Where these new commands are not supported by IE8 or IE7 that information is included in the text since those two browsers might still have to many users for you to ignore. So few people using other browsers fail to keep their browser up to date that lack of support in older versions of other browsers will not have any significant affect.

There is a link to jsBin at the bottom right of all the pages. This site provides an easy way to test your JavaScript code online without needing to create an entire web page to run a simple test.

Replace A Node

we have looked at how to delete nodes from the web page and also how to add new nodes into the web page. The replaceNode command allows you to do both types of update simultaneously.

Add Before The Current Node

The second and slightly more complicated way to add new content into the web page is used where you want to add the new content at the same level as existing content where you know the node that you want to insert the content before.

Add A Child Node

There are two ways you can add the nodes that you have built into the actual web page. The easier of the two is where you want to add the new content as a child of something already in the page where you can use the same appendChild command you used for combining the nodes […]

Create A Document Fragment

The one node type that never actually appears in a web page is a document frafment node. It is easy enough to combine nodes together before adding them to the web page (so as to have the entire update appear at once) when the nodes you are creating are all contained as children of one […]

Combining Nodes

Just being able to create new nodes representing the component parts of a web page is notusually enough by itself to achieve our desired result. There are situations such as preloading images where the image element doesn’t need to be attached into the web page to be useful but most of the time we need […]

This site is © copyright Stephen Chapman - Felgall Pty Ltd 2011-2015.

Privacy Policy | Terms and Conditions

You are welcome to use any the example JavaScript from this site in the scripts for your site or any that you develop for others but may not use the longer example scripts that contain a copyright notice in any other way without permission.