i need the full dom node path of element

前端 未结 1 383
我寻月下人不归
我寻月下人不归 2021-01-03 03:12

i need to search the html document for

text here

and then output the full node path (CSS or XPATH)

for is

相关标签:
1条回答
  • 2021-01-03 03:37

    Ok try this:

    var path = [];
    
    var el = document.getElementById('myNode');
    
    do {
        path.unshift(el.nodeName + (el.className ? ' class="' + el.className + '"' : ''));
    } while ((el.nodeName.toLowerCase() != 'html') && (el = el.parentNode));
    
    alert(path.join(" > "));
    
    0 讨论(0)
提交回复
热议问题