-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
「素のJavaScript + DOM入門」を 2024年度bootcampに向けて加筆・修正 (#179)
* 「DOM」に関して細かい表現の修正 * DOMの講義のまとめにおける、`addEventListener`についての説明をわかりやすく * JavaScriptで要素の属性を設定する節を追加 去年時間が余り気味だったので内容を足しました
- Loading branch information
Showing
4 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script type="module"> | ||
const postContentsInput = document.getElementById("postContents"); | ||
const doPostButton = document.getElementById("doPost"); | ||
doPostButton.addEventListener("click", (event) => { | ||
const postContents = postContentsInput.value; | ||
const p = document.createElement("p"); | ||
|
||
const deleteButton = document.createElement("button"); | ||
const deleteButtonText = document.createTextNode("X"); | ||
deleteButton.appendChild(deleteButtonText); | ||
deleteButton.addEventListener("click", () => { | ||
document.body.removeChild(p); | ||
}); | ||
p.appendChild(deleteButton); | ||
|
||
const flameButton = document.createElement("button"); | ||
const flameButtonText = document.createTextNode("🔥"); | ||
flameButton.appendChild(flameButtonText); | ||
flameButton.addEventListener("click", () => { | ||
p.setAttribute( | ||
"style", | ||
` | ||
color: red; | ||
font-size: 200%; | ||
font-weight: bold; | ||
` | ||
); | ||
}); | ||
p.appendChild(flameButton); | ||
|
||
const text = document.createTextNode(postContents); | ||
p.appendChild(text); | ||
document.body.appendChild(p); | ||
}); | ||
</script> | ||
<title></title> | ||
</head> | ||
<body> | ||
<input id="postContents" type="text" placeholder="いまどうしてる?"> | ||
<button id="doPost">投稿する</button> | ||
</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