简体   繁体   English

标记DOM节点以供将来查询

[英]Tagging a DOM node for future querying

I want to be able to 'tag' any position in the browser with the mouse pointer and then being able to highlight this place in the future. 我希望能够用鼠标指针在浏览器中“标记”任何位置,然后将来能够突出显示该位置。

How can I 'capture' this DOM location in a mouseDown event? 如何在mouseDown事件中“捕获”此DOM位置?

Thank you. 谢谢。

You can use the 'target' property of the MouseEvent to get the top-most element in the DOM at the position where the mouse was clicked. 您可以使用MouseEvent的'target'属性来获取DOM中位于顶部的元素,该元素位于单击鼠标的位置。

let highlightedEl;

window.addEventListener('mousedown', function(event) {
   highlightedEl = event.target;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM