Greasy Fork is available in English.

Discussions » Creation Requests

Add attribute to HTML when BODY has a specific class

§
Posted: 19 April 2020

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: 19 September 2020

what is the website that you want the run the script on?

Post reply

Sign in to post a reply.