I have stopped refreshing the page by using e.preventDefault but the code is not executing as I want. Here is the most important part
Here is the complete code
<div class="page">
<form action="">
<input type="text" id="input-field" />
<input type="submit" value="Add Task" />
</form>
<section class="tasks" id="tasks"></section>
</div>
//here variables
let submitt =document.querySelector("input[type='submit']")
let val =document.getElementById("input-field");
let clickk =document.getElementById("cli");
let divv = document.createElement("div");
divv.title = val.value;
divv.id = "iddd";
divv.className ="classone";
//append the text in the div
divv.append(val.value)
divv.style.cssText = "width:100px;height:50px;background:red;color:white;"
let sec = document.getElementById("tasks")
//func to create new div
submitt.addEventListener("submit",function(e){
sec.append(divv)
e.preventDefault();
})
hi,sounds like the submit button does not trigger the submit event as only the form can listen submit event you should listen submit on form, or use click
submitt.addEventListener("click",function(e){
sec.append(divv)
e.preventDefault();
})