Select Object ID from multiple Object IDs

Solved
Highlighted
Excursionist
20 0 3

I have the current HTML code:

<div class="container" onMouseOver"testfunction(this)">
   <img id=test1 />
   <div id=test2>
       <iframe id=test3></iframe>
    </div>
</div>

 

and the current Javascript function:

// This way every container in the page change always the first id=image of the page

function testfunction(obj)
{
   $('#test1').css("display","none"); 
}

 

How can I get the current object image id, is it possible using this type of setup?

already tried a few options but none of them works properly:

$('#' + 'obj.test1').css("display","none");
$(obj.test1).css("display","none");

 

0 Likes
Highlighted
Shopify Partner
2419 525 671

This is an accepted solution.

Hey @DaamnShop,

Remove javascript mouse over function from div and try the following jquery code.

$(".container").mouseover(function() {
    var img = $(this).find("img"), // select images inside .container
        imglen= img.length; // check if they exist
    if( imglen > 0 ){
        // images found, get id
        var attrID = img.first().attr("id"); // get id of first image       	
        $( "#"+attrID ).hide();
    } else {
        // images not found
    }
});

 

Try if this works.

 

Thanks!

 

 

If helpful then please Like and Accept Solution.
Do you need custom changes on store ? Hire me.
Feel free to Contact me on dmw.webartisan@gmail.com
Follow us on Instagram @dmw.webartisan
0 Likes
Highlighted
Excursionist
20 0 3

Hey @dmwwebartisan!

Already fixed it with "$(obj).find("img").css("display","none");"

 

Thanks for your awnser!

1 Like