admin管理员组文章数量:1293557
I have an element that I want to update the innerhtml text and icon but my tag is being ignored.
document.getElementById("nextBtn").innerHTML = "Next
<i class="icon icon--right icon-arrow-right"></i>";
}
I have an element that I want to update the innerhtml text and icon but my tag is being ignored.
document.getElementById("nextBtn").innerHTML = "Next
<i class="icon icon--right icon-arrow-right"></i>";
}
Share
Improve this question
edited Feb 13, 2021 at 13:29
pretzelhammer
15.2k16 gold badges53 silver badges103 bronze badges
asked Jul 24, 2018 at 1:36
DumbDevGirl42069DumbDevGirl42069
9595 gold badges25 silver badges54 bronze badges
2
- Replace the outer double quotes of your HTML string with single quotes. – Robby Cornelissen Commented Jul 24, 2018 at 1:38
- "Next <i class="icon icon--right icon-arrow-right"></i>" should probably be 'Next <i class="icon icon--right icon-arrow-right"></i>' – Deadweight Commented Jul 24, 2018 at 1:38
3 Answers
Reset to default 4You need to escape the inner double quotes "
in your string, or change your outer quotes to single quotes '
; Examples:
document.getElementById("nextBtn").innerHTML = "Next <i class=\"icon icon--right icon-arrow-right\"></i>";
document.getElementById("nextBtn").innerHTML = 'Next <i class="icon icon--right icon-arrow-right"></i>';
Your HTML string should be formatted with single quotes instead of double quote.
Current is:
document.getElementById("nextBtn").innerHTML = "Next
<i class="icon icon--right icon-arrow-right"></i>";
Change to:
document.getElementById("nextBtn").innerHTML = 'Next<i class = "icon icon--right icon-arrow-right" ></i>';
You must put single quotes instead of double quote
document.getElementById("nextBtn").innerHTML = 'Next<i class = "icon icon--right icon-arrow-right" ></i>';
本文标签: javascriptHow can I add html tags using innerHTMLStack Overflow
版权声明:本文标题:javascript - How can I add html tags using .innerHTML? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741570370a2385974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论