3

Is there an event after CSS rules applied to all elements in the DOM ? i know that the binding $(window).load(), from jQuery, is fired when all js and css files are loaded.

But not when they are applied (there is a small delay of some milliseconds between applying and inlcuding dynamically, such as: $('#design').attr('href', 'style.css') // design is an <link href="otherstyles.css">).

2 Answers 2

3

As per here, you could grab the contents of the CSS file with AJAX and then use jQuery's built in complete call to tell when the CSS has loaded.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, good approach, but no solution / workaround for the question. :)
2

Such an event does not exist.

  • For all attribute changes, you can listen to the DOMAttrModifed mutation event.
  • Another option is to monitor specific style properties in an periodic function (interval),
  • Another method is to modify the jQuery.fn.css method, to intercept style changes via the jQuery API. This assumes that all relevant CSS property updates are done via jQuery.

    (function($){
        var $css = $.fn.css;
        $.fn.css = function(a,c) {
            if (c == null) return $css.call(this, a);
    
            return this.each(function() {
                var $this = $(this);
                // Your function logic...
                // ...
                // Call original method
                $css.call($this, a, c);
            });
        };
    })(jQuery);
    

3 Comments

but the DOMAttrModifed event is just fired when the DOM element is directly styled, such as style="color:red"?
Yes... It is fired only when the attribute is modified
@M.Myer Also when the style is changed via e.g. document.body.style.color = 'red'; or $('body').css('color','red')..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.