2

This may seem like a noob question, but I can't seem to do anything about it. I know quite some javascript and I'm been trying this JQuery plugin which checks if two elements overlap. http://jquer.in/helpful-jquery-plugins-for-html5-websites/overlaps/ I have this code:

$('#elm1').overlaps('#elm2')

The thing is how do I get the value from it. When a try an alert with it in a variable I get [object Object] and when I put it in a function I just get the code. Thanks

1 Answer 1

1

Well, it's not so noob question, as this plugin returns value in a non-trivial way:

The second mode is to compare one set of elements against another and return only the elements that overlap.

$('#div1').overlaps('#div2');

In this example, if #div1 and #div2 overlap, the returned jQuery object will have both of them. If not, only #div1.

So the solution is to check the length of the plugin's resulting object - and compare it with sum of lengths of the compared jQuery objects. If these are the same, the elements overlap; if not, they don't. )

In this particular example, you can just compare result's length with 2, like this:

if ( $('#div1').overlaps('#div2').length === 2 ) { // they overlap }

... as in valid DOM there can be exactly one element with a given ID.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This wasn't actually the problem. The thing was that one element was in a div. I don't know why that changed anything, but it worked after I took it out. And instead of returning the elements that were overlapping it retuned one's and zero's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.