[英]How do I change an element's text through JavaScript?
<section id="section1" data-nav="Section 1" class="your-active-class">
<div class="landing__container">
<h2>Section 1</h2>
<p>Lorem ipsum dolor sit amet</p>
<p>Aliquam a convallis justo.</p>
</div>
</section>
我尝试过 textContent 和 innerHTML,我尝试通过 ID、类和标签获取元素,但没有任何效果。 我很确定我错过了一些东西。 我如何更改标题中的段落以及标题本身?
试试这段代码,将段落的 id 属性粘贴到 getElementById 中。
var paragraph = document.getElementById("id-of-your-paragraph");
paragraph.innerHTML = "Hello its a new text!";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.