VS追加的JQuery的appendChild [英] Append Vs AppendChild JQuery

查看:232
本文介绍了VS追加的JQuery的appendChild的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一些示例code:

Here's some sample code:

function addTextNode(){
    var newtext = document.createTextNode(" Some text added dynamically. ");
    var para = document.getElementById("p1");
    para.appendChild(newtext);
    $("#p1").append("HI");
}

<div style="border: 1px solid red">
    <p id="p1">First line of paragraph.<br /></p>
</div>

什么是之间的差额追加的appendChild

任何实时场景?

PS:可能是一个愚蠢的问题,只是想知道确切的区别

PS: May be a silly question just want to know the exact difference

推荐答案

的主要区别是,的appendChild 是一个DOM方法和追加是一个jQuery的方法。第二个使用第一个,你可以在jQuery的源$ C ​​$ C见

The main difference is that appendChild is a DOM method and append is a jQuery method. The second one uses the first as you can see on jQuery source code

append: function() {
    return this.domManip(arguments, true, function( elem ) {
        if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
            this.appendChild( elem );
        }
    });
},

如果您正在使用您的项目jQuery库,你将永远使用是安全的追加添加元素的页面时。

If you're using jQuery library on your project, you'll be safe always using append when adding elements to the page.

这篇关于VS追加的JQuery的appendChild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆