<!-- Наш элемент, у которого есть псевдоэлемент after -->
<div class="element-for-click">
<span>Текст</span>
</div>
.element-for-click{
position: relative;
pointer-events: none;
background:red;
padding:20px;
}
.element-for-click:after {
content: 'Псевдоэлемент';
position: absolute;
padding:20px;
background-color: #4caf50;
cursor: pointer;
pointer-events: auto;
text-align: center;
top: 0;
right:10%;
color: #FFF;
font-weight: bold;
}
document.querySelector('.element-for-click').addEventListener('click', ()=>{
alert('Клик по псевдоэлементу');
});
<a href="#item1" onclick="activeList(event,this)" > add class to text 1 </a>
<a href="#item2" onclick="activeList(event,this)"> add class to text 2 </a>
<a href="#item3" onclick="activeList(event,this)" > add class to text 3 </a>
function activeList(e,element) {
e.preventDefault();
let li_id = element.getAttribute('href').substr(1);
document.querySelectorAll('.list li').forEach( (item)=>{
item.classList.toggle("active", item.id == li_id );
});
}
const navLink = document.querySelectorAll('.m_scrollspy ul .nav-link');
console.log(navLink);
for (let i = 0; i < navLink.length; i++) {
navLink[i].onclick = () => {
// Удаляем класс у всех
navLink.forEach(function(el){
el.classList.remove('active');
});
//Добавляем класс выбранному
if (!navLink[i].classList.contains('active')) {
navLink[i].classList.add('active')
}
}
}
body{
overflow-x: hidden;
margin: 0;
}
.element {
height: 70px;
width: 270px;
border-radius: 15px;
margin-top: 10px;
background-color: red;
transform: translateX(-100%);
animation: nudge 5s linear;
}
.element:nth-child(2){
-webkit-animation-delay: 5s;
-moz-animation-delay: 5s;
-o-animation-delay: 5s;
animation-delay: 5s;
}
.element:nth-child(3){
-webkit-animation-delay: 10s;
-moz-animation-delay: 10s;
-o-animation-delay: 10s;
animation-delay: 10s;
}
@keyframes nudge {
100% { transform: translateX(100vw); }
}
<style>
в head или body, а то у Вас где-то между