-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblog.js
More file actions
41 lines (35 loc) · 1.35 KB
/
blog.js
File metadata and controls
41 lines (35 loc) · 1.35 KB
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
33
34
35
36
37
38
39
40
41
$( document ).ready(function() {
try {
let storedData = JSON.parse(localStorage.getItem('articleData'));
if (storedData !== null) {
// console.log(storedData)
addArticle(storedData);
}
else {
console.log("No data");
}
}
catch {}
});
function addArticle(storedData){
let articleList = document.querySelector('#article-cards');
for (let article in storedData.articles){
let newCardArticle = document.createElement("article");
newCardArticle.classList.add("col-4");
let newCardDiv = document.createElement("div");
newCardDiv.classList.add("card", "my-2");
let newCardBody = document.createElement("div");
let newCardTitle = document.createElement("h5");
let newCardText = document.createElement("p");
newCardBody.classList.add("card-body");
newCardTitle.classList.add("card-title");
newCardTitle.innerText = storedData.articles[article].articleTitle;
newCardText.classList.add("card-text");
newCardText.innerText = storedData.articles[article].articleText;
newCardBody.append(newCardTitle);
newCardBody.append(newCardText);
newCardDiv.append(newCardBody);
newCardArticle.append(newCardDiv);
articleList.append(newCardArticle);
}
}