开发者

How to set elements html content from a string using JS?

开发者 https://www.devze.com 2023-02-10 02:44 出处:网络
Before: <div id=\"foo\"></div> 开发者_C百科After: <div id=\"foo\"><a href=\"www.stackoverflow.com\">best site eva</a></div>

Before:

<div id="foo"></div>

开发者_C百科After:

<div id="foo"><a href="www.stackoverflow.com">best site eva</a></div>

How to accomplish this with pure JS (no jQuery)?


There are a number of ways, probably the simplest is

document.getElementById("foo").innerHTML = '<a href="www.stackoverflow.com">best site eva</a>';
0

精彩评论

暂无评论...
验证码 换一张
取 消