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

前端 未结 4 502
花落未央
花落未央 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 07:13

    You could do this, if your HTML is really that simple:

    var textarea = document.getElementById('id_name').getElementsByTagName('textarea')[0];
    textarea.value = "hello world";
    

    There's also a "getElementsByClassName()" in newer browsers that could be used to find the "class_name"

    element, from which you'd do the "getElementsByTagName()" call.

提交回复
热议问题