Skip to content
Advertisement

How I can show a innerHTML inside another one?

Question: In this code I´m traying to show the local storage in DOM, how I can show the “li” of the second for inside of the “ul” in the first for?

to show it like this? :

JavaScript

This is the code I wrote, if you see in the case both innerHTML obviouly will be separate and I dont want that.

JavaScript

Advertisement

Answer

Another way to do this kind of thing without concatenating strings all the time is to use document.createElement() and appendChild().

Note this uses textContent which prevents XSS attacks as it is not parsed as HTML.

See this minimal example.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement