var img = document.getElementById('myimg'); var anchor = document.createElement('A'); anchor.href = '#'; img.parentNode.insertBefore(anchor, img); anchor.appendChild(img);