0

var css = "";
for (var j = 0; j < document.styleSheets.length; j++) {
    var cssRules = document.styleSheets[j].cssRules;
    for (var i = 0; i < cssRules.length; i++) {
        css += cssRules[i].cssText;
    }
}

I can get all css codes on a website with above code. How can apply it to a specific element

bng
  • 109
  • 5
  • What exactly do you mean? Do you want to style one element with css? Please elaborate on your question so we can help you. – rpm192 Jun 06 '18 at 20:13
  • I want to get all css codes of an element. – bng Jun 06 '18 at 20:16
  • Possible duplicate of https://stackoverflow.com/questions/2952667/find-all-css-rules-that-apply-to-an-element https://stackoverflow.com/questions/4482374/is-it-possible-to-find-css-rules-from-an-html-node-via-javascript – Ajanth Jun 06 '18 at 20:16
  • To add all css classes to an element you must use this syntax: `.className = class` where `class` is the name of the class. If you would add more than one class, separate them with spaces, like "test demo" – Federico B. Jun 06 '18 at 20:19

0 Answers0