Skip to main content

Posts

Showing posts with the label CSS

Selecting and manipulating CSS pseudo-elements such as ::before and ::after using jQuery

You could also pass the content to the pseudo element with a data attribute and then use jQuery to manipulate that: In HTML: <span> foo </span> In jQuery: $ ( 'span' ). hover ( function (){ $ ( this ). attr ( 'data-content' , 'bar' ); }); In CSS: span : after { content : attr ( data-content ) ' any other text you may want' ; } If you want to prevent the 'other text' from showing up, you could combine this with seucolega's solution like this: In HTML: <span> foo </span> In jQuery: $ ( 'span' ). hover ( function (){ $ ( this ). addClass ( 'change' ). attr ( 'data-content' , 'bar' ); }); In CSS: span . change : after { content : attr ( data-content ) ' any other text you may want' ; } Ref : https://stackoverflow.com/questions/5041494/selecting-and-manipulating-css-pseudo-elements-such-as-before-and-after-usin