Change the Value of h1 Element within a Form with JavaScript

后端 未结 6 1173
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 11:37

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 elemen

相关标签:
6条回答
  • 2021-02-02 11:38

    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.

    0 讨论(0)
  • 2021-02-02 11:40

    You may try the following:

    document.getElementById("your_h1_id").innerHTML = "your new text here"
    
    0 讨论(0)
  • 2021-02-02 11:43

    You can also use this

    document.querySelector('yourId').innerHTML = 'Content';
    
    0 讨论(0)
  • 2021-02-02 11:45

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

    0 讨论(0)
  • 2021-02-02 11:46
    document.getElementById("myh1id").innerHTML = "my text"
    
    0 讨论(0)
  • 2021-02-02 11:55

    Try:

    
    document.getElementById("yourH1_element_Id").innerHTML = "yourTextHere";
    
    
    0 讨论(0)
提交回复
热议问题