JQuery select pseudo-element :after

AiD

I want to select pseudo-element :after

This is my css :

show-more:after
{
    content : (" > ");
}

JQuery code

$(function(){
    $('.show-more:after').click(function() {
        alert("Yes");
    }); 
});
MartaGom

It's not possible to bind directly to pseudo-elements, since those are not part of the DOM, but the desired effect can be approximated by binding to a parent element and testing for an offset related to the element that the :after acts upon:

The following renders as ELEMENT++, where clicking on "ELEMENT" and "++" each triggers different behavior:

<span>ELEMENT</span>
span::after {
  content: '++';
  position: absolute;
}

span.c1 {
  background: yellow;
}

span.c2::after {
  background: orange;
}
const span = document.querySelector('span');

span.addEventListener('click', function (e) {
    if (e.offsetX > span.offsetWidth) {
        span.className = 'c2';
    } else {
        span.className = 'c1';
    }
});

Interactive: http://jsfiddle.net/wC2p7/1/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select text in ::before or ::after pseudo-element

From Dev

Select an element after appending it in jquery

From Dev

Modify CSS of the :after pseudo-element using jQuery

From Dev

Modify CSS of the :after pseudo-element using jQuery

From Dev

How to remove element after pseudo-content with jQuery

From Dev

Pseudo element content with JQuery

From Dev

Pseudo element ::after has no height

From Dev

:after pseudo element not working in Safari

From Dev

Firefox ::after pseudo element not working

From Dev

Vertically align :after pseudo element

From Dev

:after pseudo element is not showing up

From Dev

after pseudo element not appearing in code

From Dev

after pseudo element not working in webview

From Dev

:after pseudo element not working in Safari

From Dev

Padding after linebreak with pseudo element

From Dev

Jquery select original matched element after modi

From Dev

modify pseudo select :after in javascript

From Dev

Update CSS of Pseudo Element with jQuery

From Dev

jQuery pseudo select throws exception

From Dev

jQuery pseudo select throws exception

From Dev

Hide pseudo after element when hovering this element

From Dev

Select the first CSS element using a pseudo class

From Dev

pseudo classes not working on select and radio element

From Dev

:after pseudo element creating twin circle

From Dev

Is it possible to have a :after pseudo element on a button?

From Dev

Is it possible to have an :after pseudo element on a button?

From Dev

Adding box-shadow to a :after pseudo element

From Dev

Can I nest the pseudo-element after?

From Dev

Image overlay using :after pseudo-element