html - Modify CSS selector :after with JavaScript -
how access or modify pseudo-selectors :after , :hover of css of element through javascript (please no jquery).
example
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>progress bar example</title> <style type="text/css"> .progressbar { position: relative; width: 100px; height: 10px; background-color: red; } .progressbar:after { content: ""; position: absolute; width: 25%; height: 100%; background-color: blue; } </style> </head> <body> <div id="progressbar" class="progressbar" onclick="this.style.width='90%';"></div> </body> </html>
like see want use somethink progress bar, can't exchange/add/remove second class element. access the width property of progressbar:after (with :after selector) class directly through js. how?
you give try:
edited
//create new style element var style = document.createelement("style"); //append style document.head.appendchild(style); //take stylesheet object sheet = style.sheet //add rule stylesheet -- changed line .insertrule sheet.insertrule('.progressbar::after { width: 50% }', 0);
Comments
Post a Comment