Updated March 2nd 2007
- It is a shorthand function for
document.getElementById. To get a reference to an element, just supply the
idof the element you’re looking for:
- A function to get all elements with a certain class name. More thoroughly described in The Ultimate getElementsByClassName.
- A function to add a class name to an element. It automatically takes into consideration if the element already has that class, and doesn’t apply it again if that’s the case. It also adds necessary spaces if the element already has other class names. Called like this:
- A function to remove a class name from an element. It automatically removes the class name and any eventual trailing space. If the
classNameproperty of the element starts or ends with a space after this operation has been completed, it removes them as well. Called like this:
- A function to get all elements with a certain attribute, and, if you want to, a certain value in that attribute as well. More thoroughly described in Monday code giveaway: getElementsByAttribute.
- A way to prevent the default behavior of an element; for instance, stopping the behavior of a link. Just pass in the event as a parameter:
- A very handy way to find out the rendered CSS styles on an element. Described in detail in Get the rendered style of an element.
- Support for
Array.pushin IE 5.0
- If IE 5.0 is part of your target audience, support for the
pushmethod of the
Arrayis added. Note: it is only applied to web browsers who doesn’t already support it.