function onReady() { var imgs = $(`p>img`) imgs .after(appendExpandButton) .next() .on('click', onExpandButton); imgs.parent().addClass(`img-container`); $(`#expand-img button`).on(`click`, onHideImgExpand); } function appendExpandButton(img) { return `` } function onExpandButton(e) { var imgSrc = this.getAttribute(`data-img`); $(`#expand-img img`).attr(`src`, imgSrc); $(`#expand-img`).show(0); } function onHideImgExpand() { $(`#expand-img`).hide(500); } (function() { $(document).ready(onReady) })()