728x90
๋ฐ์ํ
XPATH ๋ฌธ๋ฒ์ผ๋ก ๋จ์ผ ์์ ๊ฐ์ ธ์ค๊ธฐ
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]"));
XPATH ๋ฌธ๋ฒ์ผ๋ก ๋ค์ค ์์ ๊ฐ์ ธ์ค๊ธฐ
function getElementsByXPath(xpath, parent)
{
let results = [];
let query = document.evaluate(xpath, parent || document,
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0, length = query.snapshotLength; i < length; ++i) {
results.push(query.snapshotItem(i));
}
return results;
}
let items = getElementsByXPath("//*"); // return all elements on the page
์ถ์ฒ:
https://sensitivity-dev.tistory.com/21
Javascript XPath๋ฅผ ์ด์ฉํด์ Dom Element ๊ฐ์ ธ์ค๊ธฐ
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
sensitivity-dev.tistory.com
How to use document.evaluate() and XPath to get a list of elements?
I'm using the document.evaluate() JavaScript method to get an element pointed to by an XPath expression: var element = document.evaluate( path, document, null, XPathResult.
stackoverflow.com
728x90
๋ฐ์ํ
'๐ฅ๏ธํ๋ก ํธ์๋ > HTML | CSS | JAVASCRIPT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์๋ฐ์คํฌ๋ฆฝํธ - GET ํ๋ผ๋ฏธํฐ ์ถ์ถํ๊ธฐ (1) | 2023.10.26 |
---|---|
HTML - ํฐ์คํ ๋ฆฌ ๋คํฌ๋ชจ๋ ํ ๊ธ ๋ฒํผ (0) | 2023.09.30 |
์๋ฐ์คํฌ๋ฆฝํธ - ์๋ฐ์คํฌ๋ฆฝํธ ๋๋ ํ ์ฌ์ดํธ(obfuscator.io) (0) | 2023.09.05 |
CSS - ์ธ๊ธฐ ์๋ ๋์์ธ ํ๋ ์์ํฌ(Tailwind CSS) (0) | 2023.08.28 |
CSS - ๋ฏธ๋์ด์ฟผ๋ฆฌ ํ์ธ ์ฌ์ดํธ(mediaqueriestest.com) (0) | 2023.08.28 |