Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created August 24, 2012 20:47
Show Gist options
  • Save jpetto/3455451 to your computer and use it in GitHub Desktop.
Save jpetto/3455451 to your computer and use it in GitHub Desktop.
DOM Demo #1
<!DOCTYPE html>
<html>
<head>
<title>DOM Demo</title>
</head>
<body>
<form id="form1">
<input type="text" id="user_name" value="" />
<button type="submit" id="submit">Get It</button>
</form>
<ul id="names"></ul>
<script>
document.querySelector("#user_name").focus();
var names = document.querySelector("#names");
document.querySelector("#form1").onsubmit = function(e) {
e.preventDefault();
var user_name = document.querySelector("#user_name").value;
var li, text;
li = document.createElement("li");
text = document.createTextNode(user_name);
li.appendChild(text);
names.appendChild(li);
document.querySelector("#user_name").value = '';
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment