-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (41 loc) · 1.58 KB
/
Copy pathscript.js
File metadata and controls
53 lines (41 loc) · 1.58 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
47
48
49
50
51
52
53
let myForm = document.getElementById("add-post-form")
myForm.addEventListener("submit", onSubmit)
function onSubmit(ev){
ev.preventDefault()
console.log("recived")
addDivRecipe()
}
function addDivRecipe(){
//get form input
let nameInput = document.getElementById("recipeName")
let imageInput = document.getElementById("recipesImg")
let descriptionInput = document.getElementById("description")
let websiteInput = document.getElementById("url")
//creat box div with elements
let newDivRecipe = document.createElement("div")
let newNameRecipe = document.createElement("h3")
let newImgRecipe = document.createElement("img")
let newDescriptionRecipe = document.createElement("p")
let newWebsiteRecipe = document.createElement("a")
//fill the value in the box
newImgRecipe.setAttribute("src",imageInput.value)
newNameRecipe.innerText = nameInput.value
newDescriptionRecipe.innerText = descriptionInput.value
newWebsiteRecipe.innerText = websiteInput.value
//append box into html
newDivRecipe.appendChild(newNameRecipe)
newDivRecipe.appendChild(newImgRecipe)
newDivRecipe.appendChild(newDescriptionRecipe)
newDivRecipe.appendChild(newWebsiteRecipe)
//add class to the new div
newDivRecipe.classList.add("Recipe")
//get divRecipes
let Recipe = document.querySelector(".Recipes")
//add the new div box to divRecipes
Recipe.appendChild(newDivRecipe)
//reset the form
nameInput.value = ""
imageInput.value = ""
descriptionInput.value = ""
websiteInput.value = ""
}