Access the css ":after" selector with jQuery -
this question has answer here:
i have following css:
.pagemenu .active::after { content: ''; margin-top: -6px; display: inline-block; width: 0px; height: 0px; border-top: 14px solid white; border-left: 14px solid transparent; border-bottom: 14px solid white; position: absolute; right: 0; }
i'd change border-width of top, left, , bottom border using jquery. selector use access element? tried following doesn't seem working.
$('.pagemenu .active:after').css( { 'border-top-width': '22px', 'border-left-width': '22px', 'border-right-width': '22px' } )
you can't manipulate :after
, because it's not technically part of dom , therefore inaccessible javascript. can add new class new :after
specified.
css:
.pagemenu .active.changed:after { /* selector more specific, takes precedence on other :after */ border-top-width: 22px; border-left-width: 22px; border-right-width: 22px; }
js:
$('.pagemenu .active').toggleclass('changed');
update: while it's impossible directly modify :after
content, there ways read and/or override using javascript. see "manipulating css pseudo-elements using jquery (e.g. :before , :after)" comprehensive list of techniques.
Comments
Post a Comment