I have a set of images with various widths. I want them 100% width for responsiveness, but no larger that their actual size.
I tried:
$("#mainImg").on('load', function() {
var natWidth = $(this).get(0).naturalWidth;
alert(natWidth);
});
But nothing alerts.
I also tried this, again with no alert:
var myImage = document.getElementById("mainImg");
myImage.addEventListener('load', function() {
alert('My width is: ', this.naturalWidth);
});
Obviously, I'm missing something!
Once I can grab the width, I assume I can easily use it to set the max-width for the image.