-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
58 lines (53 loc) · 1.87 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// DOM elements
const contentForm = document.getElementById('contentForm');
const titleInput = document.getElementById('titleInput');
const contentInput = document.getElementById('contentInput');
const imageURLInput = document.getElementById('imageURLInput');
const videoURLInput = document.getElementById('videoURLInput');
const contentContainer = document.getElementById('contentContainer');
// Content array to store the entered content
let contentArray = [];
// Function to display content
function displayContent() {
contentContainer.innerHTML = '';
contentArray.forEach((content) => {
const blogElement = document.createElement('div');
blogElement.classList.add('blog');
let blogHTML = `<h3>${content.title}</h3>`;
if (content.imageURL !== '') {
blogHTML += `<img src="${content.imageURL}" alt="Blog Image">`;
}
if (content.videoURL !== '') {
blogHTML += `<iframe src="${content.videoURL}" frameborder="0" allowfullscreen></iframe>`;
}
blogHTML += `<p>${content.content}</p>`;
blogElement.innerHTML = blogHTML;
contentContainer.appendChild(blogElement);
});
}
// Function to add content
function addContent(title, content, imageURL, videoURL) {
const newContent = { title, content, imageURL, videoURL };
contentArray.push(newContent);
displayContent();
clearForm();
}
// Function to clear the form
function clearForm() {
titleInput.value = '';
contentInput.value = '';
imageURLInput.value = '';
videoURLInput.value = '';
}
// Event listener for form submission
contentForm.addEventListener('submit', (e) => {
e.preventDefault();
const title = titleInput.value.trim();
const content = contentInput.value.trim();
const imageURL = imageURLInput.value.trim();
const videoURL = videoURLInput.value.trim();
if (title !== '' && content !== '') {
addContent(title, content, imageURL, videoURL);
}
clearForm();
});