var parent = img.parentNode; var a = parent.replaceChild(document.createElement('a'),img); a.href = 'www.ru'; a.appendChild(img);