The majer component of the DOM are :
The object model focuses on collections of elements, a hierarchy of groupings that the elements fall into. The most important of these collections are:-
- The all collection :- Each element object has an all collection that contains all the elements that are beneath that element in the hierarchy.
- The children collection :- children collection that contains only the elements that are direct descendants of that element.
Example
<HTML>
<BODY>
<DIV>
<P>Some text in a
<B>paragraph</B>
</P>
<IMG id=image1 src=”mygif.gif”>
</DIV>
<IMG id=image2 src=”mygif.gif”>
</BODY>
</HTML>
- the div object contains (and is the parent of) the p object and the img object called image1.
- image1 and the p are children of the div. The img object called image2, however, is a child of the body object.
- the b would be in the div object’s all collection, but would not appear in the div object’s children collection. Similarly, the div is a member of the body object’s children collection, but the p is not.
Internet Explorer supports the all collection whereas the W3C standard uses the getElementById() method. Describe the difference this makes to accessing a particular HTML element in JavaScript.
In Internet Explorer the HTML elements on a Web page that are the source of the events, and the types of events that are generated, have been greatly expanded. Previously, only a small set of HTML elements could generate events, such as anchors, image maps, form elements, applications, and objects. With the Internet Explorer event model, every HTML element on the page can be the source for a full set of mouse and keyboard events. Where as the getElementById() method allows users to access html element by tag element only
Difference between the keypress and keydown event?
- keypress Fires when the user presses an alphanumeric key.( Presses and releases a key (full down-and-up cycle). However, if a key is held down, multiple onkeypress events are fired.)
- Keydown Fires when the user presses a key. ( Only a single event is fired, even if the key is held down.)
What is meant by event bubbling?
Event bubbling as a new way to handle events. This technique is used to process events in their user interfaces. Previously, if an HTML element generated an event, but no event handler was registered for it, the event would disappear, never to be seen again. Event bubbling simply passes these unhandled events to the parent element for handling. The event continues up (“bubbles up”) the element hierarchy until it is handled, or until it reaches the topmost object, the document object..
How do you cancel an event?
To cancel an event, we set the Window.event.cancelBubble property to “true” in the event handler. unless canceled, events will bubble up the hierarchy and be handled by all parent elements registered to the event, even if the event has already been handled.