开发者

Problem getting image's width to work using jQuery

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})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜