Created
February 21, 2015 17:02
-
-
Save kswedberg/9d06fef8977215f6bb15 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/xonicozowe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<form action="?"> | |
<div class="user"> | |
<input id="user" name="user" type="text" placeholder="user"> | |
</div> | |
<div class="password"> | |
<input id="password" name="password" type="password" placeholder="password"> | |
</div> | |
</form> | |
<p> | |
<button id="replace">Replace Inputs</button> | |
</p> | |
<script id="jsbin-javascript"> | |
var btn = document.getElementById('replace'); | |
var i = 0; | |
var replaceInputs = function replaceInputs() { | |
var inputs = { | |
user: 'text', | |
password: 'password' | |
}; | |
i++; | |
Object.keys(inputs).forEach(function(id) { | |
var el = document.getElementById(id); | |
var div = document.getElementsByClassName(id)[0]; | |
div.removeChild(el); | |
el = document.createElement('input'); | |
el.name = id; | |
el.placeholder = id + i; | |
el.id = id; | |
el.type = inputs[id]; | |
div.appendChild(el); | |
div = el = null; | |
}); | |
}; | |
btn.addEventListener('click', replaceInputs, false); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var btn = document.getElementById('replace'); | |
var i = 0; | |
var replaceInputs = function replaceInputs() { | |
var inputs = { | |
user: 'text', | |
password: 'password' | |
}; | |
i++; | |
Object.keys(inputs).forEach(function(id) { | |
var el = document.getElementById(id); | |
var div = document.getElementsByClassName(id)[0]; | |
div.removeChild(el); | |
el = document.createElement('input'); | |
el.name = id; | |
el.placeholder = id + i; | |
el.id = id; | |
el.type = inputs[id]; | |
div.appendChild(el); | |
div = el = null; | |
}); | |
}; | |
btn.addEventListener('click', replaceInputs, false);</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var btn = document.getElementById('replace'); | |
var i = 0; | |
var replaceInputs = function replaceInputs() { | |
var inputs = { | |
user: 'text', | |
password: 'password' | |
}; | |
i++; | |
Object.keys(inputs).forEach(function(id) { | |
var el = document.getElementById(id); | |
var div = document.getElementsByClassName(id)[0]; | |
div.removeChild(el); | |
el = document.createElement('input'); | |
el.name = id; | |
el.placeholder = id + i; | |
el.id = id; | |
el.type = inputs[id]; | |
div.appendChild(el); | |
div = el = null; | |
}); | |
}; | |
btn.addEventListener('click', replaceInputs, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment