4. Accessing Properties
Join the Discussion
Exactly which properties are available when you access an HTML container from a web page via the getElementById method depends on the type of element that theid is attached to. Most commonly an id will be attached to a div tag but sometimes you will find it more convenient to attach it to a different tag.
The following code illustrates some of the basic properties are available for all objects. (The properties are shown coded in alert statements simply because it produces a short piece of code that you can run to illustrate the effect, they can be coded in whatever way that you need to to achieve your desired result).
var x = document.getElementById('myfield');
In some instances these refer to an object contained within our currently referenced container or an object in which our current container can be found. In those instances we can then reference the properties of that object.
All of the attributes and all of the child nodes of our object can also be accessed if required from the attributes and childNodes arrays that are also available.
document.getElementById('myfield').title = 'New tooltip text';
We will look at a couple of particularly useful properties in more detail in the next couple of tutorials.