place html in javascript strings?

dom-manipulation, html, hyperlink, javascript

Solution

Looks fine and works here. You may want to consider mixing single quotes instead of escaping the double quotes, but that's just a preference.

document.getElementById('mydivtag').innerHTML = "<li><a href='someLink'>Some Link</a></li>";

Problem

I need to place html in a javascript string. Specifically, I would like to add an HTML link to a div tag with javascript. html: ``` <div id="mydivtag"></div> ``` javascript: ``` document.getElementById('mydivtag').innerHTML = "<li><a href=\"someLink\">Some Link</a></li> "; ``` Am I formatting the html link I am adding through javascript correctly?

Original source