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
<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
querySelectorreturns the first element that satisfies the selector in the parameter. In this case, it is aninputelement with thetype="text"attribute. Please note that this is only an example. In your markup, this input may haveidorclassattributes 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
|