{"id":7930,"date":"2015-11-10T12:23:45","date_gmt":"2015-11-10T12:23:45","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/10\/is-it-possible-to-listen-to-a-style-change-event-open-source-projects-guard-listen\/"},"modified":"2015-11-10T12:23:45","modified_gmt":"2015-11-10T12:23:45","slug":"is-it-possible-to-listen-to-a-style-change-event-open-source-projects-guard-listen","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/10\/is-it-possible-to-listen-to-a-style-change-event-open-source-projects-guard-listen\/","title":{"rendered":"Is it possible to listen to a &#8220;style change&#8221; event?-open source projects guard\/listen"},"content":{"rendered":"<p>Is it possible to create an event listener in jQuery that can be bound to any style changes? For example, if I want to &#8220;do&#8221; something when an element changes dimensions, or any other changes in the style attribute I could do:<\/p>\n<pre><code>$('div').bind('style', function() {\n    console.log($(this).css('height'));\n});\n\n$('div').height(100); \/\/ yields '100'\n<\/code><\/pre>\n<p>It would be really useful.<\/p>\n<p>Any ideas?<\/p>\n<p><strong>UPDATE<\/strong><\/p>\n<p>Sorry for answering this myself, but I wrote a neat solution that might fit someone else:<\/p>\n<pre><code>(function() {\n    var ev = new $.Event('style'),\n        orig = $.fn.css;\n    $.fn.css = function() {\n        $(this).trigger(ev);\n        return orig.apply(this, arguments);\n    }\n})();\n<\/code><\/pre>\n<p>This will temporary override the internal prototype.css method and the redefine it with a trigger at the end. So it works like this:<\/p>\n<pre><code>$('p').bind('style', function(e) {\n    console.log( $(this).attr('style') );\n});\n\n$('p').width(100);\n$('p').css('color','red');\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Is it possible to create an event listener in jQuery that can be bound to any style changes? For example, if I want to &#8220;do&#8221; something when an element changes dimensions, or any other changes in the style attribute I could do: $(&#8216;div&#8217;).bind(&#8216;style&#8217;, function() { console.log($(this).css(&#8216;height&#8217;)); }); $(&#8216;div&#8217;).height(100); \/\/ yields &#8216;100&#8217; It would be really [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7930","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7930"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7930\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}