Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You might have expected a simple utility method for resizing an element but there isn’t one. The $.resize() method is a handler for the onresize event. Unless you’re using $.animate(), you’ll have to code your own.
To resize an element just change its height and width attributes using $.css(). For example, to shrink the width of an existing element you could do the following:
var w = $(“#myElem”).css(“width”); w = parseInt(size.replace(“px”,””)) - 10; $(“#myElem”).css(“width”, w-10);
But this has the inherent disadvantage of returning a string with a unit, for example, pixels. By using the $.height() and $.width() methods, you can get the height and width of an element, making it easier to resize:
var w = $(“#myElem).width() - 10; $(“#myElem”).width(w);