tags:

views:

461

answers:

1

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.

+4  A: 

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