dom - Use jQuery to get selected element's hierarchy position/number? -
please bear me. i'm trying best explain need, i'll need few updates op.
i want position of selected element in hierarchy. example, if have total of 4 hyperlinks within entire html document, , hover on third link, want "html > body > a:eq(2)" - 2 signifying 3rd hyperlink element.
and no, index() doesn't trick.
i have tried this code little tweaking , this: "html > body > a", cannot find function return position.
how position of selected element within hierarchy of similar elements? (i not know if that's right terminology.) need traverse dom , perform manual match if x==y kinda thing
<a href=#">link1</a> <a href=#">link2</a> <a href=#">link3</a> <a href=#">link4</a> i use code kinds of html elements, not hyperlinks.
if have given element , want know nth link in document, can this:
function whichlink(el) { return $("a").index(el); } this form of .index(el) returns item in jquery object matches passed in element. searches jquery object find matching element. since jquery object sorts elements in document order, give position in document of given link.
if you're trying different, please clarify question further.
Comments
Post a Comment