Share
Facebook
Twitter
LinkedIn
Whatsapp
Instagram
Messenger

জাভাস্ক্রিপ্ট


The Document Object is a powerful tool for manipulating HTML and XML documents in JavaScript. By providing methods and properties for working with elements and modifying the document itself, it allows you to create dynamic and interactive web pages. With a little practice and experimentation, you can quickly become proficient in using the Document Object to create rich and engaging web experiences.


The Document Object Model (DOM) is a programming interface for HTML and XML documents. In JavaScript, the Document Object represents the HTML or XML document itself, and provides a variety of methods and properties that allow you to manipulate the content and structure of the document. Getting started with the Document Object To get started with the Document Object in JavaScript, you can use the "document" global variable. This variable represents the current document and provides access to all of its elements and properties. For example, to get the title of the document, you can use the following code:

উদাহরণ


var title = document.title;

কোড এডিটর


Similarly, to get the URL of the document, you can use:

উদাহরণ


var url = document.URL;

কোড এডিটর



Working with elements

The Document Object also provides methods for working with HTML elements. For example, to get an element by its ID, you can use the getElementById() method:

উদাহরণ


var element = document.getElementById("myElement");

কোড এডিটর


This will return a reference to the element with the ID "myElement". You can then use this reference to modify the element's properties, such as its innerHTML or className. Another useful method is getElementsByTagName(), which allows you to retrieve all elements of a certain type (such as all "div" elements):

উদাহরণ


var divs = document.getElementsByTagName("div");

কোড এডিটর


You can then loop through the resulting array of elements and modify their properties as needed.


Manipulating the document

In addition to getting and manipulating elements, the Document Object provides methods for modifying the document itself. For example, to create a new element and add it to the document, you can use the createElement() and appendChild() methods:

উদাহরণ


var newElement = document.createElement("div");
newElement.innerHTML = "This is a new element.";
document.body.appendChild(newElement);

কোড এডিটর


This will create a new "div" element with the content "This is a new element." and add it to the end of the document's "body" element.