I'm trying to load and resize an image using jQuery.
I have this code:
var myImg = $("#myImage");
myImg.attr("src", "/Content/TestImage.jpg");
myImg.attr("width", "750px");
The image is being loaded, but the width attribute is not taking effect. I've tried with both a width being defined in the CSS (i.e., width: 200px;) and without a width being defined.
I've also tried setting the width before setting the src attribute, but th开发者_StackOverflowat didn't make any difference either.
Anyone have any suggestions as to what the issue might be?
Try the following:
myImg.width(750);
your code works for me: http://jsfiddle.net/JtN26/
Set the width using CSS like this
myImg.css({width:750})
精彩评论