DOM find element by Xpath

后端 未结 1 686
旧巷少年郎
旧巷少年郎 2021-01-14 14:54

I\'m new to DOM querying and I\'m wondering if it is possible to query DOM elements directly by Xpath in a similar way to the below-mentioned code?

document.         


        
1条回答
  •  一整个雨季
    2021-01-14 15:30

    The equivalent statement using only XPath would be

    xPathResult = document.evaluate('//*[@id="searchInput"]', document);
    if(xPathResult){
         element = xPathResult.iterateNext();
    }
    

    Have a look at the Intro to XPath in the browser on MDN for some more examples and usages.

    0 讨论(0)
提交回复
热议问题