-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (24 loc) · 1.1 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
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('blog-form');
const resultDiv = document.querySelector('.display');
form.addEventListener('submit', (e) => {
e.preventDefault();
const title = document.getElementById('title').value;
const content = document.getElementById('content').value;
const image = document.getElementById('image').value;
const video = document.getElementById('video').value;
// Create a new blog post element
const postDiv = document.createElement('div');
postDiv.className = 'blog-post';
postDiv.innerHTML = `
<h3>Name : ${title}</h3>
<h4>Description : ${content}</h4>
${image ? `<img src="${image}" alt="${title}" width="200" height="200" />` : ''}
${video ? `<iframe width="200" height="200" src="${video}"> </iframe>` : ''}
`;
// Append the new blog post to the result section
resultDiv.appendChild(postDiv);
// Clear form inputs
form.reset();
});
});