JavaScript : DOM and BOM



<<----: DOM IN JAVASCRIPT :---->>

1. Window Vs Document
2. DOM Vs BOM
3. DOM Navigation
4. Searching and getting Element Reference

🟠Window :-

🟢Window is the main container or we can say the global object and 
any operation to entire browser window can be part of window obj.

🟢All the members like object,methods or properiesIf they are the 
part of window obj then we do not refer the window object.

🟢Window has methods,properties and objectexsetTimeout() or setInterval()
are the methodswhere as Documents is the object of the window and it also has
a screen object with properties describing the physical display 

🟠Document :-

🟢Where the DOM is the child of window obj.

🟢Where in the DOM we need to refer the document,if we want to use the
document objmethod or properties.

🟢Document is just the object of the global object that is windowwhich deals
with the document,the HTML elements themselves.

DOM vs BOM :-

👉 The DOM is the Document Object Modelwhich deals with the document,
the HTML element themselves, egdocument and all traversal you 
would do in itevents,etc.

For Ex:
change the background color to red
document.body.style.background = "red";

👉 The BOM is the Browser Object Modelwhich deals with browser components
aside from the documentlike historylocationnavigator and screen 
(as well as some other that vary by browser) . OR
In simple meaning all the Window operation which comes under BOM are performed 
Using BOM


Navigation Through the DOM :-

1document.documentElement
     return the Element that is the root element to the document.
2document.head
3: document.body
4: document.body.childNodes (include tab,enter and whiteSpace)
     list of the direct children only
5document.children (without text nodesonly regular Elements)
6document.childNodes.length


Searching and getting Element Reference :-










Interview Questions :-
QDifference Between getElementById And querySelectot

🔹 What is getElementById()?
Syntax :-
elemet = document.getElementById(id);

returns a reference to the element by its ID.
If the element with the specific ID is not in the document,
it will return null.

🔹 What is querySelector()?
Syntax:
element = document.querySelector(selectors);
Return the first element with the document 
that matchs the specified group of selectors,
or null if no matches found.