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.
jQuery width() Method The width() method sets or returns the width of the selected elements. When this method is used to return width, it returns the width of the FIRST matched element.
There is no command for changing an image size. Image dimensions are 'properties' which can be expressed in either the HTML <img> element, as width="150" height="100" attributes in the tag; or, the CSS as style rules applying to specific images.
Sometimes, it is required to fit an image into a certain given dimension. We can resize the image by specifying the width and height of an image. A common solution is to use the max-width: 100%; and height: auto; so that large images do not exceed the width of their container.
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);
$(".img1").css('height','10');
$(".img1").css('width','10');
OR
$(".img1").attr('height','10');
$(".img1").attr('width','10');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With