Ep 01. B급 개발

Javascript XPath를 이용해서 Dom Element 가져오기

B급 감성 2018. 5. 13. 05:37


Javascript XPath를 이용해서 Dom Element 가져오기


function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

console.log( getElementByXpath("//html[1]/body[1]/div[1]") );