-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsScript.js
More file actions
46 lines (34 loc) · 1.33 KB
/
Copy pathjsScript.js
File metadata and controls
46 lines (34 loc) · 1.33 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
42
43
44
45
46
// let tbody = document.querySelector("body")
let myForm = document.getElementById("add-post-form")as HTMLFormElement
myForm.addEventListener("submit", onSubmit)
function onSubmit(ev){
ev.preventDefault()
console.log("recived")
addDivImg()
}
function addDivImg(){
//get form input
let inputImage = document.getElementById("inputImage") as HTMLInputElement
let inputCap = document.getElementById("inputHeader") as HTMLInputElement
let inputText = document.getElementById("inputText") as HTMLInputElement
//creats box div with elements
let newDiv:HTMLDivElement = document.createElement("div")
let newImg:HTMLImageElement = document.createElement("img")
let newHead:HTMLHeadingElement = document.createElement("h5")
let newText:HTMLParagraphElement = document.createElement("p")
//fill the box
newImg.setAttribute("src",inputImage.value)
newHead.innerText = inputCap.value
newText.innerText = inputText.value
//order in html
newDiv.appendChild(newImg)
newDiv.appendChild(newHead)
newDiv.appendChild(newText)
newDiv.classList.add("class_new")
let gallery_Container = document.querySelector(".container") as HTMLDivElement
gallery_Container.appendChild(newDiv)
//reset input
inputImage.value = ""
inputCap.value = ""
inputText.value = ""
}