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

137
Views
Draggable returning null on CreateElement

It's returning null when the createElement are dropped in their container. But the other elements that are in my html files are dragging correctly except for the elements create with the javascript

window.addEventListener("load", ()=>{
    const Element = document.querySelectorAll( "#Data" )
    const Drop = document.querySelectorAll( "#Drop" )
    const AddBug = document.getElementById( "AddBug" )
    let DraggedItem = null

    AddBug.addEventListener("click", ()=>{
        const BugInput = document.getElementById("BugInput").value
        const Wrapper = document.getElementById("Wrapper")
        const NewDiv = document.createElement("span")
        NewDiv.classList.add("Data")
        NewDiv.setAttribute("id", "Data")
        NewDiv.setAttribute("draggable", "true")
        NewDiv.innerText = BugInput
        Wrapper.append(NewDiv)
    })
    
    for( let i=0; i<Element.length; i++ ){
        const Item = Element[i]

        Item.addEventListener("dragstart", () =>{
            console.log("DragStart")
            DraggedItem = Item
            console.log(DraggedItem)
            setTimeout(()=>{ Item.style.display = "none" },0)
        })
        Item.addEventListener("dragend", ()=>{
            console.log("dragend")
            setTimeout(()=>{
                DraggedItem.style.display = "block"
                DraggedItem = null
            },0)
        })

        for ( let j=0; j<Drop.length; j++ ){
            const list = Drop[j]

            list.addEventListener( "dragover", ( e )=>{ e.preventDefault() })
            list.addEventListener( "dragenter", ( e )=>{ e.preventDefault() })
            list.addEventListener( "drop", ()=>{ list.append(DraggedItem) })
        }
    }

})
about 4 years ago · Santiago Gelvez
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!