---
title: "清空dom源码解析"
author: "小丑鱼0703"
date: "2015-04-04T17:06:12Z"
tags: []
categories: ["Web前端"]
slug: "dom"
draft: false
lastmod: "2015-04-04T17:07:15Z"
id: 2199355
url: "https://wangjingyi.iteye.com/blog/2199355"
---

jquery中empty()是采用逐个移除子元素实现的
zepto中empty()是采用直接innerHtml=''实现的

一起来看一下:


```jquery

empty:function(){
        var elem,i=0;
        for(;(elem = this[i]) != null; i++) {
                if(elem.nodeType === 1){
                                             jQuery.cleanData(elem.getElementsByTagName("*"));

                 }
                 while(elem.firstchild){
                              elem.removeChild(elem.firstchild);
                 }
        }
}

```



```zepto

empty:function(){
        return  this.each(function(){
                this.innerHtml=''
        })
}
```