Search code examples
javascriptjquerycoordinatesoffsetchildren

Get all the children top and left


I want to get all children offset top inside parent by using jquery and javascript but I only found a few ways to use loop and it's very long so I believe there is something shorter for this

And i never actually learn jquery from A to Z so if it has any solution can you tell me ? Thanks

I want achieve some thing like

var top = $("#storage").children().each().offset().top;

And it will way more beautiful if it is already sorted to array by jquery something like

var top = [122,213,123];

Solution

  • You can use .map (and .get to convert to a regular array).

    let top = $("#storage").children().map((_, el) => $(el).offset().top).get();