Selecting element from DOM with JavaScript and XPath

前端 未结 2 1020
无人共我
无人共我 2020-12-24 07:46

I\'m trying to figure out how to select the textarea in the code below using xpath and JavaScript (which is the only option here).


    
2条回答
  •  情话喂你
    2020-12-24 08:03

    The evaluate method does not return a DOM node as you seem to expect. You would need

    var element = document.evaluate( '//body//form/p/textarea' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
    if (element != null) {
      element.value = '...';
    }
    

提交回复
热议问题