I'm seeking the most effective method to dynamically update a stylesheet using JavaScript. Currently, I am aware that this can be achieved with querySelectorAll(), which retrieves all elements on a page that match a specific query. However, one drawback of this approach is that if new elements are added to the DOM, their styles must be manually replaced, leading to a messy situation.
It seems that document.styleSheets might hold the key to my issue, but I am struggling to find a straightforward way to locate and modify CSS rules or properties. While it provides functions like insertRule and addRule, I'm uncertain about how to utilize them effectively for replacing CSS properties.
Any assistance on this matter would be greatly appreciated!
PS:
While I prefer utilizing JavaScript for this task, I am open to using jQuery as well. I can always figure out a way to convert jQuery code to JavaScript.
Background:
I frequently use websites like waffle.io and am not satisfied with their themes. In an attempt to customize these sites using a Chrome Extension and JavaScript, simply changing HTML attributes isn't sufficient since waffle.io regularly updates its DOM. My goal is to run a script once at the start and ensure that newly added elements also adhere to the updated styles. Given this constant DOM changes, I believe updating CSS rules/properties within the stylesheet itself is crucial (although I could be mistaken).
If my objective is still unclear, please don't hesitate to let me know.