Note that there are some explanatory texts on larger screens.

plurals
  1. POmaking a new div draggable, tried everything
    primarykey
    data
    text
    <p>Hello stackoverflow comunity.</p> <p>I am working on some code that makes draggable resizeable divs. I have it working with the divs that are created originally, but the newly added divs arent becomming draggable.</p> <p>Here is ALL my code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script&gt; var id = 4; function drag(ev) { ev.dataTransfer.setData("Text",ev.target.id); } function drop(ev) { ev.preventDefault(); ev.target.appendChild(document.getElementById(ev.dataTransfer.getData("Text"))); } function change(div) { var divw=parseInt(div.style.width); var divh=parseInt(div.style.height); var imgw=divw-10; var imgh=divh-10; div.children[0].style.width=imgw; div.children[0].style.height=imgh; div.style.border="dotted 3px grey"; } function addimg() { var main = document.getElementById('main'); var div = document.createElement('div'); div.onmouseout = function() {this.style.border=0}; div.ondragstart = function() {drag(event)}; div.onmousemove = function() {change(this)}; div.setAttribute('draggable', true); div.id = 'div'+id; id+=1; div.style.styleFloat = 'left'; div.style.cssFloat = 'left'; div.style.resize = 'both'; div.style.overflow = 'hidden'; div.style.height = '110px'; div.style.width = '110px'; div.innerHTML = '&lt;img draggable="false" style="width: 100px; height: 100px" src="https://www.google.com/images/srpr/logo11w.png" /&gt;'; main.appendChild(div); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;center&gt; &lt;div ID="main" ondragover="event.preventDefault()" ondrop="drop(event)" style="width:900px; height:900px; border: dashed 1px lightgrey;" overflow="auto"&gt; &lt;div onmouseout="this.style.border=0" draggable="true" ondragstart="drag(event)" onmousemove="change(this)" id="div1" style="float:left; resize:both; overflow:hidden; height: 110px; width:110px"&gt; &lt;textarea onblur="this.nextElementSibling.innerHTML=this.innerHTML" style="resize:none; width: 100px; height: 100px"&gt;&lt;/textarea&gt; &lt;p style="background-color: blue"&gt;&lt;/p&gt; &lt;/div&gt; &lt;div style="clear:both"&gt;&lt;/div&gt; &lt;div onmouseout="this.style.border=0" draggable="true" ondragstart="drag(event)" onmousemove="change(this)" id="div2" style="float:left; resize:both; overflow:hidden; height: 110px; width:110px"&gt; &lt;img draggable="false" style="width: 100px; height: 100px" src="https://www.google.com/images/srpr/logo11w.png" /&gt; &lt;/div&gt; &lt;div onmouseout="this.style.border=0" draggable="true" ondragstart="drag(event)" onmousemove="change(this)" id="div3" style="float:left; resize:both; overflow:hidden; height: 110px; width:110px"&gt; &lt;img draggable="false" style="width: 100px; height: 100px" src="https://www.google.com/images/srpr/logo11w.png" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/center&gt; &lt;button onclick="addimg()"&gt;add an image&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>the issue is that the new divs aren't draggable.</p> <p>P.S. if you use jquery, please explain it very detailed, i have no experience with it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload