i need to search the html document for <p class="content"> text here </p>
and then output the full node path (CSS or XPATH)
for isntance
html > body > div class ="something" > table > tr > p class="content"
i tried with nokogiri but it doesn't handle the class and other attributes well..
i need a parser that does this without problem.
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(" > "));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With