/jQuery-Watch-Plugin

Watches elements for changes in the attributes defined and executes callback

Primary LanguageJavaScriptGNU General Public License v2.0GPL-2.0

#Watch Plugin

This plugin lets you listen for when a CSS property, or properties, changes on element. It utilizes Mutation Observers or the DOMAttrModified / propertychange events, when available, and fallsback to polling utilizing setInterval().

There is both a jQuery-specific plugin as well as a library agnostic version of this plugin available.

Original blog post can be found here

Example Uses

More examples can be found here

jQuery Usage

// Watch for width or height changes and log values
$('div').watch('width height', function(){
	console.log(this.style.width, this.style.height);
});

Library Agnostic Usage

// Watch for width or height changes and log values
var div = document.querySelectorAll('div');
watch( div, 'width height', function(){
	console.log(this.style.width, this.style.height);
});

License

Copyright (c) 2013 Darcy Clarke
Dual licensed under the MIT and GPL licenses.