JSFiddle - React, Tailwind, and code Playground

by Purag Moumdjian

HTML

<div class="container">
    Click me!
    <img id="firstIMG">
    <img id="secondIMG">
</div>

JavaScript

$(document).on("click", ".container", function(){
    var img = $(this).find("img"), // select images inside .container
        len = img.length, // check if they exist
        arr = [];
    if( len > 0 ){
        // images found, get id
        img.each(function(){
            arr.push( $(this).attr("id") ); 
        });
        alert(arr);
    } else {
        // images not found
    }
});