jQuery - condition for .attr src

0 votes
155 views
added Jun 28, 2019 in jQuery by LC Marshal Captain (25,770 points)
//shorter way of doing it
var img = $('.img');

if (img.src == 'oldimage.jpg'){
    //do this
    img.src = 'newimage.jpg';
}

//conventional way
if (img.attr('src') == 'oldimage.jpg') {
    img.attr('src','newimage.jpg');
}

 

1 Response

0 votes
responded Jun 28, 2019 by LC Marshal Captain (25,770 points)
if(btnIco.attr('src') == closeIco) {
  $(btnIco).attr('src', defIco);
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...