How to set a value of the textarea without id by javascript?

前端 未结 4 512
花落未央
花落未央 2021-01-13 06:26

Typically we run javascript code to set any value:

document.getElementById(\'id_name\').value = \"...\";

But I have a page like this:

4条回答
  •  长情又很酷
    2021-01-13 06:55

    There are a few differerent possibilities and many context:

    document.querySelector("textarea").value = "Your text";// Set a first textarea find in a page.
    
    document.querySelectorAll("textarea").value = "Your text";// Set all textarea find in a page.
    
    document.getElementById('myForm').querySelector("textarea").value = "Your text";// Set a textarea into a form: (frequently used).
    

提交回复
热议问题