简体   繁体   中英

Insert a child element without using appendChild?

Supose i have this HTML code:

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

And i want to append a new button, without using appendChild function (just curiosity). 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? 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.

How appendChild works? 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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