It is best to use parseInt . The jQuery .width() and .height() functions work quite well.
In addition, it would be nice to encapsulate a selection of these values ββin autonomous functions:
.minHeight() , .minHeight( size ) , .minHeight( function() ).maxHeight() , ....minWidth() , ....maxWidth() , ...
Like this:
(function($, undefined) { var oldPlugins = {}; $.each([ "min", "max" ], function(_, name) { $.each([ "Width", "Height" ], function(_, dimension) { var type = name + dimension, cssProperty = [name, dimension.toLowerCase()].join('-'); oldPlugins[ type ] = $.fn[ type ]; $.fn[ type ] = function(size) { var elem = this[0]; if (!elem) { return !size ? null : this; } if ($.isFunction(size)) { return this.each(function(i) { var $self = $(this); $self[ type ](size.call(this, i, $self[ type ]())); }); } if (size === undefined) { var orig = $.css(elem, cssProperty), ret = parseFloat(orig); return jQuery.isNaN(ret) ? orig : ret; } else { return this.css(cssProperty, typeof size === "string" ? size : size + "px"); } }; }); }); })(jQuery);
And your code will turn into:
alert($('#<%=lstProcessName.ClientID%>').parent('.column4').width()); alert($('#<%=lstProcessName.ClientID%>').parent('.column4').minWidth()); alert($('#<%=lstProcessName.ClientID%>').parent('.column4').width() >= $('#<%=lstProcessName.ClientID%>').parent('.column4').minWidth()); if ($('#<%=lstProcessName.ClientID%>').parent('.column4').width() >= $('#<%=lstProcessName.ClientID%>').parent('.column4').minWidth()) {
Alexander Yatkevich
source share