[英]javascript: how can I replace the select:after icon on click?
this is my icon style.这是我的图标风格。
.select::after {
/* content : "▼"; */
content: '▲';
position : absolute;
top : 0;
right : 0;
padding : 0 1em;
background : #e100ff;
color : #fff;
cursor : pointer;
pointer-events : none;
-webkit-transition: 0.25s all ease;
-o-transition : 0.25s all ease;
transition : 0.25s all ease;
}
what I want is to replace the icon, when the icon is clicked.我想要的是在单击图标时替换图标。 how can I achieve that?
我怎样才能做到这一点?
You would need to use some JS here too to update the class.您也需要在这里使用一些 JS 来更新 class。 Here's a common approach.
这是一种常见的方法。 Toggle an active class and based on that you can update the icon.
切换一个活动的 class 并在此基础上更新图标。
document.querySelector('.select').addEventListener('click', function (e) { e.target.classList.toggle('active') }, false)
.select::after { /* content: "▼"; */ content: '▲'; position: absolute; top: 0; right: 0; padding: 0 1em; background: #e100ff; color: #fff; cursor: pointer; pointer-events: none; -webkit-transition: 0.25s all ease; -o-transition: 0.25s all ease; transition: 0.25s all ease; }.select.active::after { content: '▼'; }
<span href="" class="select">Pop</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.