Best Way To Write JQuery's ReplaceWith() In Natural JavaScript


Answer :

var image = document.getElementById('imagefiles'), parent = image.parentNode, tempDiv = document.createElement('div');  tempDiv.innerHTML = "<input type='file' name='imagefiles' id='imagefiles' />"  var input = tempDiv.childNodes[0];  parent.replaceChild(input, image); 

DEMO


EDIT as per am not i am:

var image = document.getElementById('imagefiles'), parent = image.parentNode, input = document.createElement('input'); input.id = input.name = "imagefiles"; input.type = 'file';  parent.replaceChild(input, image); 

edited DEMO


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?