我刮網頁提取與特定CSSselector了這樣的內容:
$("p, h1, h2").each(function(index) {
// Do stuff
})
現在,我想要知道什麼選擇器對應於返回的對象:我想知道它是p
標記,h1
標記還是h2
標記。
我該如何做到這一點?這裏的理念是:
$("p, h1, h2").each(function(index) {
console.log("CSS Selector: ", $(this).cssSelectorName)
})
看看[TagName屬性(https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName),例如'this.tagName' –