Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load stylesheet at runtime

i have specific theme css which is required only when popup window is launches, nowhere else i'm using that css. Simply loading at the launch of website launch is waste.

Is there a way to load css only when required i.e upon opening popup window i can load the stylesheet?.

like image 829
Naruto Avatar asked Sep 13 '26 05:09

Naruto


1 Answers

Create a new element like this

var lnk=document.createElement('link');
lnk.href='path/sheet.css';
lnk.rel='stylesheet';
lnk.type='text/css';
(document.head||document.documentElement).appendChild(lnk);

Hope this helps.

like image 120
chandaniitr Avatar answered Sep 15 '26 18:09

chandaniitr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!