Sort
Profile photo for Glen R. Goodwin

Essentially, you need to make a big drop area the size of your entire page. This can be done with a large DIV tag, or you could look into whether the BODY element can receive drop events or not.

Now admittedly I have not worked with the HTML5 Drag and Drop stuff but you could do something like this:

The real problem is your usage of the appendChild method, which on a drop event will merely append the element you are dragging into the droparea as the last element.

I suspect what you are really trying to do is to have a big space where you can position things any way you want just by merely dragg

Essentially, you need to make a big drop area the size of your entire page. This can be done with a large DIV tag, or you could look into whether the BODY element can receive drop events or not.

Now admittedly I have not worked with the HTML5 Drag and Drop stuff but you could do something like this:

The real problem is your usage of the appendChild method, which on a drop event will merely append the element you are dragging into the droparea as the last element.

I suspect what you are really trying to do is to have a big space where you can position things any way you want just by merely dragging them about. This then might be more appropriate to what you want.

  1.  
  2. <div id="droparea" draggable="false" style="position: absolute; z-index: 100; left: 0px; right: 0px; top: 0px; bottom: 0px;" ondrop="drop(this, event)" ondragenter="return false" ondragover="return false"> 
  3. <div draggable="true" id="draggable1" ondragstart="drag(this,event)" style="z-index: 200; width: 200px; height: 20px; border: 2px solid red; background: none repeat scroll 0% 0% green; font-weight: bold; margin: 10px;">Drag me 1</div> 
  4. <div draggable="true" id="draggable2" ondragstart="drag(this,event)" style="z-index: 200; width: 200px; height: 20px; border: 2px solid red; background: none repeat scroll 0% 0% green; font-weight: bold; margin: 10px;">Drag me 2</div> 
  5. <div draggable="true" id="draggable3" ondragstart="drag(this,event)" style="z-index: 200; width: 200px; height: 20px; border: 2px solid red; background: none repeat scroll 0% 0% green; font-weight: bold; margin: 10px;">Drag me 3</div> 
  6. </div> 
  7. <script charset="utf-8" type="text/javascript"> 
  8. var offsetx = null, offsety = null; 
  9. function drag(target, event) { 
  10. if (!target.draggable) return; 
  11. offsetx = target.offsetLeft-event.clientX; 
  12. offsety = target.offsetTop-event.clientY; 
  13. event.dataTransfer.setData('Text',target.id); 
  14. } 
  15.  
  16. function drop(target, event) { 
  17. var id = event.dataTransfer.getData('Text'); 
  18. if (!id) return; 
  19. var e = document.getElementById(id); 
  20. e.style.position = "absolute"; 
  21. e.style.left = (event.clientX+offsetx)+"px"; 
  22. e.style.top = (event.clientY+offsety)+"px";  
  23. event.preventDefault(); 
  24. } 
  25. </script> 

The solution is to use absolute positioning instead of letting the div element manage positioning.

Profile photo for Mark Bradley

Where do I start?

I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.

Here are the biggest mistakes people are making and how to fix them:

Not having a separate high interest savings account

Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.

Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.

Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of th

Where do I start?

I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.

Here are the biggest mistakes people are making and how to fix them:

Not having a separate high interest savings account

Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.

Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.

Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of the biggest mistakes and easiest ones to fix.

Overpaying on car insurance

You’ve heard it a million times before, but the average American family still overspends by $417/year on car insurance.

If you’ve been with the same insurer for years, chances are you are one of them.

Pull up Coverage.com, a free site that will compare prices for you, answer the questions on the page, and it will show you how much you could be saving.

That’s it. You’ll likely be saving a bunch of money. Here’s a link to give it a try.

Consistently being in debt

If you’ve got $10K+ in debt (credit cards…medical bills…anything really) you could use a debt relief program and potentially reduce by over 20%.

Here’s how to see if you qualify:

Head over to this Debt Relief comparison website here, then simply answer the questions to see if you qualify.

It’s as simple as that. You’ll likely end up paying less than you owed before and you could be debt free in as little as 2 years.

Missing out on free money to invest

It’s no secret that millionaires love investing, but for the rest of us, it can seem out of reach.

Times have changed. There are a number of investing platforms that will give you a bonus to open an account and get started. All you have to do is open the account and invest at least $25, and you could get up to $1000 in bonus.

Pretty sweet deal right? Here is a link to some of the best options.

Having bad credit

A low credit score can come back to bite you in so many ways in the future.

From that next rental application to getting approved for any type of loan or credit card, if you have a bad history with credit, the good news is you can fix it.

Head over to BankRate.com and answer a few questions to see if you qualify. It only takes a few minutes and could save you from a major upset down the line.

How to get started

Hope this helps! Here are the links to get started:

Have a separate savings account
Stop overpaying for car insurance
Finally get out of debt
Start investing with a free bonus
Fix your credit

Profile photo for Lc Dmrr

Thanks to Glen R. Goodwin ! it was not exactly what I was looking for but now it works.
I decrease the counter when the content is bigger than when and I remove the element when it's equal to 1. This is what I want to do. thank you.
Here is the code

<body style="Background:#FFFFFF;">

<div id="A" ondrop="drop(this, event)" ondragenter="return false" ondragover="return false" style="position: absolute; left: 0px; top: 0px; bottom: 0px; right: 68%; background: #F0D0D0;">

<div draggable="true" id="1" ondragstart="drag(this,event)" style="z-index: 1; border: 1px solid black; background: #404040; col

Thanks to Glen R. Goodwin ! it was not exactly what I was looking for but now it works.
I decrease the counter when the content is bigger than when and I remove the element when it's equal to 1. This is what I want to do. thank you.
Here is the code

<body style="Background:#FFFFFF;">

<div id="A" ondrop="drop(this, event)" ondragenter="return false" ondragover="return false" style="position: absolute; left: 0px; top: 0px; bottom: 0px; right: 68%; background: #F0D0D0;">

<div draggable="true" id="1" ondragstart="drag(this,event)" style="z-index: 1; border: 1px solid black; background: #404040; color: white; font-weight: bold; margin: 10px; font-size: 100px; overflow: hidden; text-align: center;">3</div>

<script charset="utf-8" type="text/javascript">

function drag(target, event) {

if (!target.draggable) return;

event.dataTransfer.setData('Text',target.id);

}


function drop(target, event) {

var id = event.dataTransfer.getData('Text');

if (!id) return;


var c = document.getElementById(id);

console.log("child","id: "+c.id,event);

var val = c.innerHTML;

console.log("value","id: "+val);


if(val > 1){

c.innerHTML = val-1;

}else{

var p = event.srcElement

console.log("parent","id: "+p.id);

d = p.removeChild(c);

}

event.preventDefault();

}
</script>

</body>

About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025