.dim( [ New_Dimension ] )
Gets the Dimension of an element. Dimension not necessarily equal to the style values width and height. Dimesnion also includes padding and border width of an element
Sets an element to a particular Dimension if the new dimension is specified.
Parameters
Returns
Example 1
Find the Dimension div elements. click on the box divs to find it.
JS
HTML
CSS
$.domLoaded(function() { $.get("div").on("click", function() { // Get the dimension of clicked div var di = $.self().dim(); alert("Dimension - wid : " + di.wid + " ht : " + di.ht); }); });
Result
Example 2
Set different dimensions for a div element.
JS
HTML
CSS
$.domLoaded(function() { $.get("#btn1").on("click", function() { // Set Dimension $.get("#box").dim({wid : 400, ht : 200}); }); $.get("#btn2").on("click", function() { // Set Dimension $.get("#box").dim({wid : 50, ht : 50}); }); $.get("#btn3").on("click", function() { // Set Dimension $.get("#box").dim({wid : 100, ht : 100}); }); });
Result
| |||||||||||||||