事件监听器对CSS伪元素,如:before或:after? [英] Event listener on a CSS pseudo-element, such as :before or :after?

查看:212
本文介绍了事件监听器对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.

这篇关于事件监听器对CSS伪元素,如:before或:after?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆