Computer: Ch.5 HTML in Java Script (Notes)

 

Call by ID

·         Method:  document.getElementById('yourId')

·         Uniqueness:  IDs are intended to be unique within an HTML document. Each element should have a different ID.

·         Return Type:  This method returns a single Element object, or null if no element with the specified ID is found.

 

Call by Class Name

·         Method:  document.getElementsByClassName('yourClassName')

·         Uniqueness:  Class names are not unique; multiple HTML elements can share the same class name.

·         Return Type:  This method returns a live HTML Collection of elements that have the specified class name. Even if only one element matches, it will be returned within a collection.

 

Call by Element (Tag Name)

·         Method:  document.getElementsByTagName('yourTagName')

·         Uniqueness:  Not unique; multiple elements can share the same tag name (e.g., multiple <p> elements, multiple <div> elements).

·         Return Type:  This method returns a live HTMLCollection of elements that have the specified tag name.

 

Comments