Clarus Dignus Clarus Dignus - 1 year ago 329
Javascript Question

Output img.currentSrc of srcset using jQuery

I need to output the current source of an image using a jQuery alert:

alert($('.someclass img').attr('currentSrc'));

...however the alert is outputting undefined.

For reference, the mark-up is as follows:

<div class="someclass">
<img srcset=", 2x">

Answer Source

currentSrc is a property not an attribute. Use .prop('currentSrc')

$(function() {

<script src=""></script>
<div class="someclass">
    <img srcset=",">