tags:

views:

42

answers:

3

How to add height , width unit to image using jquery , like pixel, % ect

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); 
A: 

You can set that through CSS:

$(img).css('height', '100%');
davydepauw
what is the way to add height width both ?
Yashwant Chavan
+5  A: 

I quote the documentation:

.height( value )
value An integer representing the number of pixels, or an integer with an optional unit of measure appended (as a string).

Felix Kling
+2  A: 

To set both in one declaration:

$(img).css({
    height: '100%',
    width: '100%'
});
Tatu Ulmanen
thanks its working
Yashwant Chavan