事件监听器对CSS伪元素,如:before或:after?
问题描述:
我们假设有一个DIV,一个CSS伪元素:之前
以一个关闭的形式。我可以在伪元素上只有一个点击事件监听器吗?
Let's say a have a DIV, with a CSS pseudo-element :before
in the form of say, a close botton. Can I have a click event listener on the pseudo-element ONLY?
<div id="box"></div>
#box:before {
content:"";
position:absolute;
top:-10px;
right:-10px;
display:block;
width:20px;
height: 20px;
background: url(close.png);
}
#box {
height: 100px;
width: 100px;
}
答
伪元素不存在于DOM中,因此它没有表示它的HTMLElementNode对象。
No. The pseudo-element does not exist in the DOM so it has no HTMLElementNode object representing it.