Strona główna HTML i javascript C++ Hardware HTML i javascript Java Software SQL

Javascript - innerHTML why not use.

Added: 2012-02-03

InnerHTML is an easy way to insert data or elements to page WWW, unfortunately, it is not included in the standards of encoding pages, what can cause unexpected behavior.

If you want to party complies with the standards, you must use appendChild or removeChild to editing elements on page.

After adding tags to page www using innerHTML, this makes the disorder hierarchy of DOM, what can cause that it will not be possible to register the events. In some case else code may work correctly but can cause a lot of damage to page.

Example of error after adding tag to page using innerHTML. If you add div tag to page using document.getElementById([idElem]).innerHTML, it may not be possible registered events by addEventListner().

In the newly created scripts use appendChild, do modifying older scripts and testing.