I'm trying to get the dimensions of an image after a div is shown.
What I got:
JQUERY:
$("body").on("click", ".more-info", function(e) {
e.preventDefault();
$(".component-alt-main").show(0, function() {
$(this).find(".component-img").each(function() {
$(this).find("img").on("load", function() {
console.log("A")
});
});
});
});
HTML:
<div class="component-alt-main"> <!-- This has display none -->
<div class="container">
<div class="components">
<h3>Versiones alternativas</h3>
<div class="component-container">
<div class="component">
<div class="component-img">
<img src="modulos/topbar/[email protected]">
</div>
<p class="title">Topbar principal <b>simple</b></p>
<div class="component-text">
<p>
Puede darse el caso de que tengamos una sección dónde sólo aplique el título.
</p>
</div>
</div>
<div class="component">
<div class="component-img">
<img src="modulos/topbar/[email protected]">
</div>
<p class="title">Topbar principal <b>simple</b></p>
<div class="component-text">
<p>
Variable de un botón pulsable en el lateral derecho. No puede haber más de uno.
</p>
</div>
</div>
</div>
</div>
</div>
</div>
I'm trying to get that console.log() after I click a button (.more-info), but it's not entering. I don't know if it's because the images are already loaded (even though .component-alt-main is with display: none;). But if I try to get those image before the .show(), the width of them are 0 obviously.
There's something wrong with the code above?
PS:
I'm asking this because later on I must use AJAX to resize the images once they are loaded.
PSS:*
The console.log placed on .each() works.
.component-alt-maindiv