Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check what image was loaded in HTML picture element

I have following code in my app:

<picture>
    <source media="(max-width: 1300px)" srcSet={src.img['1']} />
    <source media="(max-width: 1599px)" srcSet={src.img['2']} />
    <source media="(max-width: 2049px)" srcSet={src.img['3']} />
</picture>

is it possible programmatically to check which of these images was loaded by browser in picture element? I have to use that image once again (now I use img['1'] by default in tooltip) but I want to avoid loading image one more time.

like image 490
magnat Avatar asked Dec 04 '25 09:12

magnat


1 Answers

Include the <img> tag inside <picture> and check its currentSrc property.

like image 101
niutech Avatar answered Dec 07 '25 00:12

niutech