我需要元素的完整dom节点路径 [英] i need the full dom node path of element

查看:92
本文介绍了我需要元素的完整dom节点路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要搜索html文档< p class =content>文本这里< / p>

i need to search the html document for <p class="content"> text here </p>

然后输出完整的节点路径(CSS或XPATH)

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

for isntance

for isntance

html > body > div class ="something" > table > tr > p class="content"

我尝试使用nokogiri,但它不处理类和其他属性

i tried with nokogiri but it doesn't handle the class and other attributes well..

我需要一个没有问题的解析器。

i need a parser that does this without problem.

推荐答案

确定尝试:

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(" > "));

这篇关于我需要元素的完整dom节点路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆