I am using this code to change the src
attribute of an img
element to data-src
, but my current solution doesn't work. I don't know what I'm doing wrong.
Any help would be appreciated.
<script>
$("img").each(function() {
$(this).attr("data-src",$(this).attr("src"));
$(this).removeAttr("src");
});
</script>
<img src="test.jpg" width="300" height="200">
I want this output:
<img data-src="test.jpg" width="300" height="200">