You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Courses/IBM-JavaScript-Essentials/README.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1378,3 +1378,47 @@ try {
1378
1378
// the message program continues after error handling is logged.
1379
1379
console.log("hello world");
1380
1380
```
1381
+
1382
+
## Document Object Model (DOM):
1383
+
1384
+
The document object model, or DOM, is a programming interface for web documents. It represents the web page so that programs like JavaScript can change the document structure, content, and style. It provides a structured representation of the web page, making it easier for developers to interact with and manipulate web content.
1385
+
1386
+
- Document:
1387
+
1388
+
1. The term document refers to a web page or any XML document such as HTML, XHTML, or XML.
1389
+
2. The DOM represents this document as a structured tree-like hierarchy with each part represented as a node.
1390
+
1391
+
- Object:
1392
+
1393
+
1. An object represents a JavaScript object that corresponds to an element, attribute, or content within the web document.
1394
+
2. Each DOM element is an element of the web page, accessible and manipulable using JavaScript.
1395
+
1396
+
- Model:
1397
+
1398
+
1. The model denotes the structured and abstract representation of a web document.
1399
+
1400
+
- How the DOM works ?
1401
+
1402
+
When a web page is loaded in a browser, the browser creates a DOM representation of the page's structure. It forms a hierarchical tree structure with the document's root as the top node.
1403
+
1404
+
- $0 variable:
1405
+
1406
+
$0 is a special variable that you can use in the browser's development console as a quick reference to the currently selected DOM element in the elements panel in web development.
1407
+
1408
+
Open console tab within developer tools and type $0 in the console. For example, if you have selected a div element in the elements panel and you type $0 in the console, it will refer to that div element. Once you have the element referenced with $0, you can interact with it using JavaScript. This includes accessing its properties or modifying its attributes.
1409
+
1410
+
- Types of node:
1411
+
1412
+
1. Document node is the top level node representing the entire web page. The entire HTML document is represented as the document node. To access the entire document using the document object, open console and type
1413
+
1414
+
```js
1415
+
var documentNode =document; // Now the entire document is accessible through the documentNode variable.
1416
+
1417
+
documentNode; // You will be able to see the entire document object.
1418
+
```
1419
+
1420
+
2. Element nodes represent HTML elements such as div, p, a, and form the bulk of the DOM structure. To access the element node select the paragraph you want to inspect and select inspect. then navigate to the console tab and enter $0. It will output the HTML code and details of that specific element.
1421
+
1422
+
3. Attribute nodes represent attributes of HTML elements including id, class, and src.
1423
+
1424
+
4. Text nodes contain the text content within elements. To retrieve the text of the selected element, use the $0.textContent command. This will give the text content.
0 commit comments