简体   繁体   English

如何获取 javascript 中元素的背景 div

[英]how to get a background div for a element in javascript

If a div(handler) is positioned on a top a div(grid cells) then how can we get our div's background div(grid cell)如果 div(handler) 位于 div(grid cells) 的顶部,那么我们如何获取 div 的背景 div(grid cell)

<div class='range-handler'>
  <div class='left-top-handler'></div>
  <div class='right-bottom-handler'></div>
</div>

在此处输入图像描述

I think that if you want to get div's background div, you must use javascript.我认为如果要获取div的背景div,必须使用javascript。

Using document.querySelector to get the target.使用document.querySelector获取目标。 And then, you can use target.parentElement to get its parent dom, or use target.children to get all his children.然后,您可以使用target.parentElement获取其父 dom,或使用target.children获取他的所有孩子。

Alternate for that is you can get element by screen coordinates,另一种方法是您可以通过屏幕坐标获取元素,

const touch = event.changedTouches[ 0 ];
document.elementFromPoint( touch.clientX, touch.clientY )

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

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