Change the Value of h1 Element within a Form with

2019-03-19 04:28发布

I have two forms on an HTML5 page. Each form has a name and an id. The second form has an h1 element, which also has a name and an id. How do I change the text of this h1 element on the second form using plain JavaScript?

5条回答
放我归山
2楼-- · 2019-03-19 05:10

You can do it with regular JavaScript this way:

document.getElementById('h1_id').innerHTML = 'h1 content here';

Here is the doc for getElementById and the innerHTML property.

The innerHTML property description:

A DOMString containing the HTML serialization of the element's descendants. Setting the value of innerHTML removes all of the element's descendants and replaces them with nodes constructed by parsing the HTML given in the string htmlString.

查看更多
不美不萌又怎样
3楼-- · 2019-03-19 05:12

Try:


document.getElementById("yourH1_element_Id").innerHTML = "yourTextHere";

查看更多
smile是对你的礼貌
4楼-- · 2019-03-19 05:14

You may try the following:

document.getElementById("your_h1_id").innerHTML = "your new text here"
查看更多
女痞
5楼-- · 2019-03-19 05:17
document.getElementById("myh1id").innerHTML = "my text"
查看更多
霸刀☆藐视天下
6楼-- · 2019-03-19 05:19

You can use this: document.getElementById('h1_id').innerHTML = 'the new text';

查看更多
登录 后发表回答