image - How to change img to amp-img with jQuery? -
accelerated mobile pages (amp) project
original
<div class="thumbnail"> <img src="myimage.jpg" alt="an image"/> </div>
result
<div class="thumbnail"> <amp-img src="myimage.jpg" width="1080" height="610" layout="responsive" alt="an image"></amp-img> </div>
how jquery ?
use .replacewith()
api replace content :
$('.thumbnail').find('img').replacewith(function () { return '<amp-img src="'+this.src+'" width="1080" height="610" layout="responsive" alt="'+this.alt+'"></amp-img>' });
Comments
Post a Comment