What is DOMContentLoaded?

 What is DOMContentLoaded?



`DOMContentLoaded` is an event that is fired when the initial HTML document has been completely loaded and parsed, without waiting for CSS style sheets, images, and sub frames to finish loading. This event is part of the Document Object Model (DOM) and is often used in JavaScript to ensure that the DOM is ready for manipulation.

How to Use `DOMContentLoaded` in JavaScript?

example Code of JavaScript to Use `DOMContentLoaded`

 

```javascript

document.addEventListener('DOMContentLoaded', function () {

    // Your code here

    console.log('DOM content has been fully loaded and is ready for manipulation.');

});

```

Why do we Use `DOMContentLoaded` in JavaScript?

By using the `DOMContentLoaded` event, you ensure that your JavaScript code runs after the HTML document has been fully loaded, but before all external resources like images and stylesheets have finished loading. This is useful because it allows you to start manipulating the DOM without waiting for all assets to be ready.