简体   繁体   English

插入子元素而不使用appendChild?

[英]Insert a child element without using appendChild?

Supose i have this HTML code: 假设我有这个HTML代码:

<div id='my-id'>
   <button> ClickMe </button>
</div>

And i want to append a new button, without using appendChild function (just curiosity). 而且我想追加一个新按钮,而不使用appendChild函数(只是出于好奇)。 Is there any way to do that? 有什么办法吗? Something like: 就像是:

var div = document.getElementById('my-id')
document.createElement('button').parentNode(div)
//That doesn't work.

How appendChild works? appendChild如何工作? It changes some element's property or what? 它会更改某些元素的属性或什么? Where can i find that information? 我在哪里可以找到该信息?

Thanks and sorry my bad english :) 谢谢,抱歉我的英语不好:)

There are other functions that insert elements into the DOM, such as insertBefore , but you do need to use one of the provided methods. 还有其他将元素插入DOM的函数,例如insertBefore ,但是您确实需要使用提供的方法之一。

How appendChild works? appendChild如何工作? It changes some element's property or what? 它会更改某些元素的属性或什么?

That's an implementation detail that is up to the individual browser. 这是实现细节,具体取决于各个浏览器。

Where can i find that information? 我在哪里可以找到该信息?

For open source browsers you could examine their source code (which is usually written in C rather than JavaScript). 对于开源浏览器,您可以检查其源代码(通常用C而不是JavaScript编写)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM