Event after applying CSS rules for elements in jQuery / Javascript

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

But not when they are applied (there is a slight delay in milliseconds between application and dynamic inclusion, for example: $('#design').attr('href', 'style.css') // design is an <link href="otherstyles.css"> ).

+2
source share
2 answers

According to here, you can grab the contents of a CSS file using AJAX, and then use jQuery's built-in full call to indicate when the CSS loaded.

+3
source

Such an event does not exist.

  • For all attribute changes, you can listen for the DOMAttrModifed mutation event .
  • Another option is to track certain style properties in a periodic function (interval),
  • Another method is to modify the jQuery.fn.css method to capture style changes using the jQuery API. This assumes that all relevant CSS property updates are done through 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); 
+1
source

Source: https://habr.com/ru/post/972208/


All Articles