javascript - Get the full dom traversal address of a node, going down from body to the node, without relying on getElementBy or $('jQuery') -
i'm writing userscript , want "address" of node, like, if web page this:
<body> <content> <a href='/something' name='element i'm interested in'> </content> </body>
how address of a
(where a
particular a
element know , can point manually, or other regular selectors) give me this: body.content.a
can use in userscript perform operations on over node gotten getelementby() method in javascript.
obviously real page more complex , can't write out. there way address either running jquery or javascript on page or browser tool?
using javascript if have element in variable , want find it's heirachy should possible traversing nodes parent chain: eg like
function getaddress(element) { var address = element.tagname; if (element.parentnode) { address = getaddress(element.parentnode) + '.' + address; } return address; } // using above function var node = document.getelementbyid("myfavouritenode"); var address = getaddress(node);
note that "address" in format suggested wont usable finding nodes or per comments on question. need specify how intend use address first.
Comments
Post a Comment