-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (23 loc) · 1.05 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("blog-form").addEventListener("submit", function(event) {
event.preventDefault();
var title = document.getElementById("title").value;
var content = document.getElementById("content").value;
var postElement = document.createElement("article");
postElement.classList.add("blog-post");
var titleElement = document.createElement("h3");
titleElement.textContent = title;
var contentElement = document.createElement("p");
contentElement.textContent = content;
postElement.appendChild(titleElement);
postElement.appendChild(contentElement);
var blogList = document.getElementById("blog-list");
blogList.appendChild(postElement);
document.getElementById("title").value = "";
document.getElementById("content").value = "";
});
});
var h1 = document.querySelector("h1");
h1.addEventListener("input", function() {
this.setAttribute("data-text", this.innerText);
});