Okay, so we learnt that JavaScript uses a hierarchical dot notation to refer to objects. In addition to the name property, objects can have other properties.
For example, an image located in a document is an object and has the following properties:
- border: value of <IMG> BORDER attribute
- height: value of HEIGHT attribute
- width: value of WIDTH attribute
- src: the URL of the image
- hspace: value of HSPACE attribute
- vspace: value of VSPACE attribute
- complete: determines whether the image has been completely loaded
- lowsrc: the URL of lower quality image specified through LOWSRC attribute
- name: the value of NAME attribute (Just to clarify… the name of an image refers to the HTML name attribute and NOT the file name. By the by, you can use the same value in the NAME attribute value and file name.)
To refer to the source of an image named logo we use:
document.logo.src
Similarly, its width is refered as:
document.logo.width
Different HTML elements have different properties. For example, a text field form object has the following properties:
- name: specifies the text field name
- value: specifies its value (the text contained in the field)
- defaultValue: determines the default text value
- type: identifies its type
To set the value of a text field, we use the = (equal too) operator as:
document.contactform.add.value = "Type your address here";
This is a JavaScript statement that instructs the browser to displays the text Type your address here in the text field add.