0

I'm successfully getting the following data:

        var pos = $('div#spotJoinSite').offset();  
        var width = $('div#spotJoinSite').width();
        var height = $('div#spotJoinSite').height();

Is it possible to combine this into one line that results in an array?

something like this:

var array = $('div#spotJoinSite').offset().width().height();

And then be able to use the array as array[0] would be offset and array[2] would be height.

Is this possible or a variation on this?

thx

1 Answer 1

2

No, that syntax isn't possible. You could improve your code, however, by only doing the selection once:

var joinSite = $('#spotJoinSite'),
    pos = joinSite.offset(),
    width = joinSite.width(),
    height = joinSite.height();

If you really wanted an array, you could get one:

var joinSite = $('#spotJoinSite'),
    details = [joinSite.offset(), joinSite.width(), joinSite.height()];
Sign up to request clarification or add additional context in comments.

Comments

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.