TriSTaR TriSTaR - 2 months ago 15
CSS Question

Add the array to the css 'content' in Jquery

I want to display the data on the css style content. I have this code:

if (ext){
switch (ext.toLowerCase())
{
case 'doc': pos = 'doc'; break;
case 'bmp': pos = 'bmp'; break;
case 'jpg': pos = 'jpg'; break;
case 'jpeg': pos = 'jpeg'; break;
case 'mp3': pos = 'mp3'; break;
case 'avi': pos = 'avi'; break;
case 'wmv': pos = 'wmv'; break;
case 'flv': pos = 'flv'; break;
case 'pdf': pos = 'pdf'; break;
case 'txt': pos = 'txt'; break;
case 'xls': pos = 'xls'; break;
case 'rar': pos = 'rar'; break;
case 'zip': pos = 'zip'; break;
default: pos = 'doc'; break;
};
fileIcon:after.css({content:'pos'})
};


});

How can i show this
case data
write to css:

.fileIcon:after
{ content: "";
}


The decision: https://jsfiddle.net/e9wjzqjd/3/ if need someone

Answer

You could append a new <style> tag to the <head>

var cssRule ='.fileIcon:after{ content:"' + pos + '";}';
$('<style>').text(cssRule).appendTo('head');

You can't directly access pseudo classes like :after in the dom using script