Return to Snippet

Revision: 16864
at August 18, 2009 05:17 by cfleschhut


Initial Code
jQuery.extend(jQuery.expr[":"], {
	"css": function(element, index, matches, set) {
		var parts = /([\w-]+)\s*([<>=]+)\s*(\d+)/.exec(matches[3]);
		var value = parseFloat(jQuery(element).css(parts[1]));
		switch (parts[2]) {
			case "<":
				return value < parseInt(parts[3]);
				break;
			case "<=":
				return value <= parseInt(parts[3]);
				break;
			case "=":
			case "==":
				return value == parseInt(parts[3]);
				break;
			case ">=":
				return value >= parseInt(parts[3]);
				break;
			case ">":
				return value > parseInt(parts[3]);
				break;
		}
	}
});

Initial URL
http://jsbin.com/ojora

Initial Description
adapted from the fantastic „Learning jQuery 1.3“ book

http://www.packtpub.com/learning-jquery-1.3/book

Initial Title
Custom jQuery Pseudo-Class :css() Selector Expression

Initial Tags
plugin, jquery

Initial Language
jQuery