开发者

Problem getting image's width to work using jQuery

开发者 https://www.devze.com 2023-03-26 01:10 出处:网络
I\'m trying to load and resize an image using jQuery. I have this code: var myImg = $(\"#myImage\"); myImg.attr(\"src\", \"/Content/TestImage.jpg\");

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

精彩评论

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

关注公众号