Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

60
Views
I want to create a div or more inside the section when I press the submit button

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();
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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();
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!