Define id for style with DOM.injectStyles

I use DOM.injectStyles to inject the styles, but the question is, can I do the injection with an id?


<style id='mystyle'>
...
</style>

I want to delete the previous one to inject style again so I need an id for finding and deleting it but now without the possibility of deletion, a new style will be added to the page that will increase the size of the page.

1 Like

At the moment the method doesn’t seem to support what you describe. But you can extend it to have the ability to treat second parameter as id. Then upon injecting the same id, we replace the old style text with new text. It could be a nice PR :smile:

For a solution for what you are trying to do, you can also do it like this.

    let styleTag = DOM.createElement('style');

    styleTag.type = 'text/css';
    styleTag.id = 'tag-id';
    styleTag.innerHtml = //your css here;

    DOM.appendNode(styleTag, document.head);
1 Like

I created a PR in here

1 Like