It is required from input type="text" to take the value entered by the user and, upon clicking on the button, add to the element using JavaScript. Tried via onClick="document.getElementById('seventhOne').innerHTML+=text;" - did not work

    1 answer 1

     <button onclick="document.getElementById('seventhOne').innerHTML+=document.querySelector('input[type=text]').value">Click</button> <input type="text" value="test "/> <div id="seventhOne">start </div> 

    • Can you please explain the algorithm of querySelector in this code? Thanks in advance - user319432
    • @ Dream1ngFly querySelector returns the first element that satisfies the selector in the parameter. In this case, it is an input element with the type="text" attribute. Please note that this is only an example. In your markup, this input may have id or class attributes to make the selector more specific. - Igor
    • @Igor I would say it works partially, because if you click more than once, you know) - Pavel Igorevich