innerHTML adds text but not HTML tags

JavascriptWeb DevelopmentFront End Scripts

Maybe, you are using += with innerHTML. Try the following:

var myNum = [1,2,3];
var myStr;
myStr = "<ul>";

for( var a in myNum)
myStr += "<li>" + a + "</li>";
myStr += "</ul>";
id("numberList").innerHTML = myStr;
raja
Updated on 29-Jan-2020 08:18:47

Advertisements