Detecting whether two divs overlap

Johannes Flood picture Johannes Flood · Dec 23, 2012 · Viewed 14.9k times · Source

Possible Duplicate:
How to detect if two divs touch with jquery?

I've spent a lot of time trying to figure out how to detect if two divs are overlapping.
I tried the gamequery plugin and used it like this:

$("#" + checkform).collision("#" + checkform + "w").each(function(){
    alert("Collision");
});

Would you use the gamequery plugin and/or how would you do it?

Answer

Niet the Dark Absol picture Niet the Dark Absol · Dec 23, 2012

Use getBoundingClientRect() on each element, and see if they overlap that way. No jQuery needed.