Greasy Fork is available in English.

चर्चा » बनवण्याच्या विनंत्या

Add attribute to HTML when BODY has a specific class

§
पोस्ट केले: 2020-04-19

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?

§
पोस्ट केले: 2020-09-19

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

उत्तर पोस्ट करा

उत्तर पोस्ट करण्यासाठी साइन इन करा.