Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
how can we run drag and drop codes with the help of html, css and a bit of javascript?
<!DOCTYPE html>
<html>
    <head>
        <title>My Web Page</title>
         <script>
            function dragstart(ev){
               ev.dataTransfer.setData("Text",ev.target.id);
            }
            function dragfinish(ev){
             ev.preventDefault();   
            }
            function dropstart(ev){
                var data = ev.dataTransfer.getData("Text");
                ev.target.appendChild(document.getElementById(data));
                ev.preventDefault();
            }
        </script>
    </head>
    <body>
    <p text-style="center"> I started to work on drag and drop</p>
<div style="width:400px;height:380px; border:2px; border-style:solid;"   id="div1" ondrop="dropstrat(event)" ondragover="dragfinish(event)"></div>  
<div style="height:300></div>
    <img id="pic1  src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTAqB_HEXzRtgLQiHn71I1-ph0cAhoiBXkMwA&usqp=CAU" width="355" height="355" draggable="true" ondragstart="dragstart(event)">
    </body>

I tried this code but have no idea what is wrong with it? can anyone help me! I wonder whether the problems roots in my web browser, upper case or lowercase, or I don't know maybe a semicolon can make problem? the thing is I can drag an element in my web page, but I cannot drop in in the div that I defined, I guess all went well except the time I wrote script.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The problem is that your

ondrop="dropstrat(event)"

instead of

ondrop="dropstart(event)"
about 4 years ago · Juan Pablo Isaza Denunciar

0

A lot of typos, missing quote etc

<!DOCTYPE html>
<html>

<head>
  <title>My Web Page</title>
  <script>
    function dragstart(ev) {
      ev.dataTransfer.setData("Text", ev.target.id);
    }

    function dragfinish(ev) {
      ev.preventDefault();
    }

    function dropstart(ev) {
      var data = ev.dataTransfer.getData("Text");
      ev.target.appendChild(document.getElementById(data));
      ev.preventDefault();
    }
  </script>
</head>

<body>
  <p text-style="center"> I started to work on drag and drop</p>
  <div style="width:400px;height:380px; border:2px; border-style:solid;" id="div1" ondrop="dropstart(event)" ondragover="dragfinish(event)"></div>
  <div style="height:300"></div>
  <img id=" pic1" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTAqB_HEXzRtgLQiHn71I1-ph0cAhoiBXkMwA&usqp=CAU" width="355" height="355" draggable="true" ondragstart="dragstart(event)" />
</body>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda