Changing the image source using jQuery

前端 未结 16 2054
天命终不由人
天命终不由人 2020-11-22 01:24

My DOM looks like this:

16条回答
  •  醉话见心
    2020-11-22 02:10

    In case you update the image multiple times and it gets CACHED and does not update, add a random string at the end:

    // update image in dom
    $('#target').attr('src', 'https://example.com/img.jpg?rand=' + Math.random());
    

提交回复
热议问题