Reputation: 51
I started working on a project a came across a strange way to include a CSS file using javascript.
Example from the project:
document.write('<link rel="stylesheet" type="text/css" href="css/plugins/jquery.datatables.css" />');
Is there any reason (advantage) to include the file this way?
Upvotes: 3
Views: 66
Reputation: 5489
This code does not include JavaScript but the CSS include...by using JavaScript. It allows to dynamically select your CSS maybe to select themes or adapt layout to the device.
Upvotes: 2
Reputation: 413
Maybe to load the stylesheet only when dataTable is displayed and avoid unnecessary request ?
Upvotes: 0
Reputation: 207923
The CSS file will only be added to the page if the user has JavaScript enabled. Bandwidth saver.
Upvotes: 4