Modification of button text



  • I can't change the text when I press the button. I used to do this:<input type='button' value='Изменить текст' onclick='test.innerText = "Он поменялся!"'>but you have to do that.

            <button1 onclick= Test.innerText = "Чтоо">
                Описание1
            </button1>
    
        &lt;br&gt;
        &lt;p id = "Test"&gt;
            Тест
        &lt;/p&gt;</code></pre></div></div></p><p>How do you change the text?</p>


  • Turn the atribut value into double quotes, and the line into single.

    <button onclick="Test.innerText = 'Чтоо'">
      Описание1
    </button>
    

    <br>

    <p id="Test">Тест</p>


    And you better do modern people:

    document.querySelector('#btn').addEventListener('click', () => {
    document.querySelector('#Test').innerText = 'Чтоо';
    });
    <button onclick="Test.innerText = 'Чтоо'" id="btn">
    Описание1
    </button>

    <br>

    <p id="Test">Тест</p>



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2