This doesn't work, but it shows you what I want to do:
$(this+":after").css('content', 'something');
Basically, I want my function to dynamically add an :after element to various matched elements.
Is there a correct way to do this?
This doesn't work, but it shows you what I want to do:
$(this+":after").css('content', 'something');
Basically, I want my function to dynamically add an :after element to various matched elements.
Is there a correct way to do this?
 
    
    You cannot use the pseudo-elements :after and :before in JavaScript (and jQuery is JavaScript, too!).
However, you can simply .append() something:
$(this).append('something');
If that's not what you want, you could put this in your CSS:
something:after { content: attr(data-after); }
Then you can use .attr('data-after', 'whatever') to modify the text used in the :after "element". Note that you cannot use .data('after', 'whatever') as it only reads attributes but never sets them.
 
    
    $(this).after('content'); is what you're looking for
