I want to know what the difference is between appendChild
, insertAdjacentHTML
, and innerHTML
.
I think their functionality are similar but I want to understand clearly in term of usage and not the execution speed.
- For example, I can use
innerHTML
to insert a new tag or text into another tag in HTML but it replaces the current content in that tag instead of appends. If I would like to do it that way (not replace) I need to use
insertAdjacentHTML
and I can manage where I want to insert a new element (beforebegin
,afterbegin
,beforeend
,afterend
)And the last if I want to create (not insertion in current tag) a new tag and insert it into HTML I need to use
appendChild
.
Am I understanding it correctly? Or are there any difference between those three?