I'm tryi开发者_开发百科ng to write a javascript code that loads several css files. But link element has no onload event, that's why I append some extra element to my document wich tells me if css files have been loaded. I wonder if there is a possibility to add only one element for all my css files and the same css rule.
In other words, is there an accumulative rule in css, i.e. the effect of it's application to dom element changes each time (i mean that the effect depends on how many times you applied this rule)?
No, there is no such accumulative rule. You may add a class many times, but the element will look like if you did it once.
If you want control over loading you could load the css files directly into the page with ajax. The ajax request will give you response if if is completed. Now you can insert the css into the document and it will be applied immediately.
Using jQuery it could be
$.ajax({
url: 'url/to.css',
dataType: text,
method: 'POST',
success: function(data) {
$('body').append('<style>' + data + '</style>');
// some more code as the css is in the page
}
});
hope that helps a bit.
精彩评论