Vicky
Vicky

Reputation: 9585

How to set height , width to image using jquery

Is there any way to set height and width of an image using jquery? The following is my code

var img = new Image();  
 // Create image
$(img).load(function(){                 
    imgdiv.append(this);
}).error(function () {  
    $('#adsloder').remove();
}).attr({ 
    id: val.ADV_ID,  
    src: val.ADV_SRC,
    title: val.ADV_TITLE,
    alt: val.ADV_ALT
});

Thanks.

Upvotes: 16

Views: 68278

Answers (3)

eQ19
eQ19

Reputation: 10691

In case the image is inside <div class="myGallery">

$('div.myGallery > img').css({ 'height': '10px', 'width': '10px' }); 

Upvotes: 1

sekhar.k
sekhar.k

Reputation: 111

$(".img1").css('height','10');
$(".img1").css('width','10');

OR

$(".img1").attr('height','10');
$(".img1").attr('width','10');

Upvotes: 11

Nick Craver
Nick Craver

Reputation: 630349

You can call the .height() and ,.width() setters:

var img = new Image();  
 // Create image
$(img).load(function(){                 
    imgdiv.append(this);
}).error(function () {  
    $('#adsloder').remove();
}).attr({ 
    id: val.ADV_ID,  
    src: val.ADV_SRC,
    title: val.ADV_TITLE,
    alt: val.ADV_ALT
}).height(100).width(100);

Upvotes: 27

Related Questions