Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created January 16, 2016 02:52
Show Gist options
  • Select an option

  • Save chikoski/4cdca3c52f8f6e502a55 to your computer and use it in GitHub Desktop.

Select an option

Save chikoski/4cdca3c52f8f6e502a55 to your computer and use it in GitHub Desktop.
appendChild の練習
var list = document.querySelector("#list");
var titleElement = document.querySelector("#title");
var registerButton = document.querySelector("#register");
function registerItem(title, dueDate){
var item = document.createElement("li");
var text = title + "(" + dueDate + ")";
item.textContent = text;
list.appendChild(item);
}
function register(){
var title = titleElement.value;
if(title != null && title.length > 0){
registerItem(title, "いつか");
}
}
registerButton.addEventListener("click", register);
<!doctype html>
<html>
<head>
<title>課題のリスト</title>
<meta charset="utf-8">
</head>
<body>
<input type="text" id="title">
<button id="register">登録</button>
<ul id="list">
</ul>
<script src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment