Greasy Fork is available in English.

Discussions » Creation Requests

Add attribute to HTML when BODY has a specific class

§
Posted:

Add attribute to HTML when BODY has a specific class

I was trying to style HTML when BODY gain a specific class. For that I need the HTML element would gain a specific attribute that css codes would recognize.

I wrote a script, but it doesn't work:

var elem = document.getElementByTagName('BODY');
var attr = elem.getAttribute('class');
if(attr !== null) {
  if(attr == some_class")
     document.getElementByTagName('HTML').setAttribute('my_attribute', 'true');
}

Could someone help me with this?

§
Posted:
what is the website that you want the run the script on?

Post reply

Sign in to post a reply.