admin管理员组文章数量:1342661
In fiddle - /, does not work as expected
var x = document.createElement("button");
x.textContent = "byyyyy";
elx = document.getElementById("el");
elx.insertAdjacentHTML('afterend', x);
In fiddle - http://jsfiddle/u3bmytnL/, does not work as expected
var x = document.createElement("button");
x.textContent = "byyyyy";
elx = document.getElementById("el");
elx.insertAdjacentHTML('afterend', x);
Share
Improve this question
edited Feb 6, 2015 at 10:53
nikhil rao
asked Feb 6, 2015 at 10:43
nikhil raonikhil rao
3913 gold badges6 silver badges9 bronze badges
3 Answers
Reset to default 9That's should resolve:
var x = document.createElement("BUTTON");
var text = document.createTextNode("byyyy");
x.appendChild(text);
elx = document.getElementById("el");
elx.insertAdjacentHTML('afterend', x.outerHTML);
The insertAdjacentHTML needs a string as second parameter, and you was passing a DOM element, so you need to get the HTML string
It is because insertAdjacentHTML
method takes a string instead of an element node reference.
MDN insertAdjacentHTML
You should put a string as the second parameter
本文标签: jqueryJavascript insertAdjacentHTML not workingStack Overflow
版权声明:本文标题:jquery - Javascript insertAdjacentHTML not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743695116a2523373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论