Clarus Dignus Clarus Dignus - 2 years ago 358
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=",">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download