---
title: "When is event DOMContentLoaded triggered"
author: "mr.a"
date: "2016-10-08T16:24:40Z"
tags: []
categories: ["Web前端"]
slug: "when-is-event-domcontentloaded-triggered"
draft: false
lastmod: "2016-10-08T16:40:29Z"
id: 2328970
url: "https://mr-a.iteye.com/blog/2328970"
---

When is event DOMContentLoaded triggered?

DOMContentLoaded 何时触发？

 

> Once the user agent stops parsing the document, the user agent must run the following steps:
> 
> 当客户端停止解析文档后， 必须执行以下几步：
> 
> 1. Set the current document readiness to “interactive” and the insertion point to undefined.
> 
> 设置当前文档的状态为“inactive” 并设置插入点为 undefined。
> 
> Pop all the nodes off the stack of open elements.
> 
>  
> 
> 2. If the list of scripts that will execute when the document has finished parsing is not empty, run these substeps:  
> 2.1 Spin the event loop until the first script in the list of scripts that will execute when the document has finished parsing has its “ready to be parser-executed” flag set and the parser’s Document has no style sheet that is blocking scripts.  
> 2.2 Execute the first script in the list of scripts that will execute when the document has finished parsing.  
> 2.3 Remove the first script element from the list of scripts that will execute when the document has finished parsing (i.e. shift out the first entry in the list).  
> 2.4 If the list of scripts that will execute when the document has finished parsing is still not empty, repeat these substeps again from substep 1.
> 
> 3. Queue a task to fire a simple event that bubbles named **DOMContentLoaded** at the Document.