I created an attribute for the img tag, as in the sample type code data-tablet,data-mobil
<div class="myDiv">
<img src="img-1.jpg" data-tablet="img-2.jpg" data-mobil="img-3.jpg">
</div>
and I want my screen to change to tablet, my img data-tabletsrc to change with, or my mobility screen to change my src withdata-mobil
MY JS
$(document).ready(function(){
$(window).resize(function(){
var tabletSrc = $(".main-carousel img").attr("data-tablet");
var mobilSrc = $(".main-carousel img").attr("data-mobil");
if($(window).width() <=768){
$('img').attr('src',tabletSrc);
}
if($(window).width() <=480 ) {
$('img').attr('src',mobilSrc);
}
});
});
click to see my work
Question: how can I do what I want, if you click that you won’t see anything?
Note: I do not want to use srcset or css
source
share