Quoting jQuery Method
As with jQuery 1.4 , the second argument can take a map consisting of superset properties that can be passed in the .attr() way. In addition, any type of event can be transmitted, and the following jQuery methods can be called: val, css, html, text, data, width , height, or offset.
So, these properties are processed by the appropriate methods, and .width() and .height() apply their values ββin the style attribute.
Follow the steps from the comments below:
At least this is a documentation error in which jQuery does not recognize a conflict between the legal properties of height and width and jQuery methods of the same name.
More appropriately, this is an API error that needs to be resolved. An error report was sent here.
Note that this only affects the optional props argument when creating items. The .attr() method works correctly with respect to width and height .
Update: jQuery has confirmed the conflict, but will not provide any fixes allowing its users to apply width and height in the props argument when creating elements.
Therefore, these properties are not supported for assignment in this way. You will need to apply these properties separately from the others in a separate call to the .attr() function, which supports them correctly.
var x = $('<img/>', { src:'some/path/to.jpg', alt:'some text' }).attr({ width:100, height:100 });
Gabriele Petrioli May 17 '11 at 21:34 2011-05-17 21:34
source share