【发布时间】:2017-07-18 23:15:42
【问题描述】:
我想得到一个html元素的准确位置,并输出那个元素的地址,逻辑是这样的。
<div id="foo">
<article>
<div>
<p>you found me</p>
</div>
</article>
<div>
这就是示例 html,现在假设用户单击了该标记上的某些内容,在这种情况下,假设用户单击了“p”标签。如何编写我的 JavaScript 来输出那个“p”标签的地址。
function getAddress(){
// code here
console.log('the user click the ')
console.log(address)
}
期望的输出:
// Console
log: the user click the
log: #foo > article > div > p
【问题讨论】:
-
任何搜索算法背后的逻辑是什么?或者你想回溯直到父母带有id?
-
@omi 基本上我想回溯直到父母带有 id
标签: javascript jquery html