I have a simple function called loadStyles() here it is:
function loadStyles(url) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = url;
link.media = 'all';
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(link);
}
I was wondering if there's another way of adding the values of certain properties except this one:
link.rel equals to ..., link.type equals to ..., etc.
I tried something like this:
function loadStyles(url) {
var link = document.createElement('link');
link += {
rel: 'stylesheet',
type: 'text/css',
href: url,
media: 'all'
};
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(link);
}
But that doesn't work. I know it's probably stupid to even try it (because my IDE says that this {....} expression is not assignable to type HTML element ^^').