How to change css pseudo elements in javascript?

I want to change below the :beforevalue of css pseudo element topusing javascript or jQuery dynamically ... how can I do this?

#buble{

height:70px;
width:980px;
background-color:#bce5a5;
display:none;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
box-shadow:0px 0px 4px #dadada;
text-indent:35px;
color:#4a8f44;
font-weight:bold;
font-size:14pt;

       }

#buble:before{

content:"";           
display:block;
position:absolute;
top:77px; /* value = - border-top-width - border-bottom-width */
left:555px; /* controls horizontal position */
border-width:11px 7px 0px; /* vary these values to change the angle of the vertex */
border-style:solid;
border-color:#bce5a5 transparent;
width:0;
height:0;
}
+4
source share
2 answers

To my knowledge, you cannot directly change the pseudo-style, but you can insert CSS into the head of the DOM in this way

JQuery

$( "div" ).click(function() {

  $('<style>p:before{top:10px}</style>').appendTo('head');

});

Mark it Demo jsFiddle

+1
source

With jQuery you need to add style to the head:

$('<style>#buble:before{top: 50px}</style>').appendTo('head');

more details

0
source

Source: https://habr.com/ru/post/1535861/


All Articles