Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image native width in jquery

With jQuery, i change the src of an image on click

$("#thumb li img").click(function() {
var newlinkimage = $(this).attr("src");

newlinkimage = newlinkimage.substring(14,17);

    $("#avant img").attr("src", 'retouche-hr' + newlinkimage + '-a.jpg');
    $("#apres img").attr("src", 'retouche-hr' +newlinkimage + '-b.jpg');

The problem is, that the NEW image width is different that the old. HOW do i get the NATIVE width of the new image (like the little arrow that get that in dreamweaver

like image 676
menardmam Avatar asked Nov 18 '25 19:11

menardmam


1 Answers

This is the plain javascript way to do it. It should be easy to integrate this into your code.

var newimage = new Image();
newimage.src = 'retouche-hr' + newlinkimage + '-a.jpg'; // path to image
var width = newimage.width;
var height = newimage.height;
like image 123
Scott Saunders Avatar answered Nov 20 '25 08:11

Scott Saunders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!