Click here to Skip to main content
15,868,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have and external syle sheet in my html page I want to update some of class property dynamically.But it is showing error while accessing rules

document.styleSheets[0].rules.length

DOMException:Failed to read the 'rules' property from 'CSSStyleSheet': Cannot access rules

Please help.

What I have tried:

document.styleSheets[0].rules.length

DOMException:Failed to read the 'rules' property from 'CSSStyleSheet': Cannot access rules
Posted
Comments
Chris Copeland 27-May-22 5:07am    
suneel kumar gupta 27-May-22 7:20am    
It's working fine when application is hosted or run from iis express Only it's not working when I write this code in html page run the page by just opening in chrome. Also same thing is working with IE.
Chris Copeland 27-May-22 8:14am    
Can you check in the developer tools console/network tabs whether the stylesheet is loading correctly? It's quite common for browsers to limit certain operations when running from a local file for security reasons. It could be your browser is either not loading the remote CSS, or your browser (ie. Chrome) is blocking access the stylesheets rules because of things like CORS.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900