1

Get the next item on the stack at an absolute position

We have the following markup:

<div class="box">
    <div id="item1">1</div>
    <div id="item2">2</div>
    <div id="item3">3</div>
</div>

      

Divs with ID item1, item2, item3 are positioned absolutely. In css, item2 has moved more to the left than item3.

Example here http://jsfiddle.net/tto8ymqa/

$('#item1').next()

will return $ ('# item2') How to get a visual NEXT item?

If the explanation is not clear, ask me :)

+3


source to share


1 answer


Here's an example function:

http://jsfiddle.net/tto8ymqa/2/

Js



var domOrder, visualOrder;
$(function() {
   domOrder = $(".box").find("DIV");
   getVisualOrder();  
})

function getVisualOrder() {
    visualOrder = domOrder.sort(function(a,b) {
        return $(a).offset().left-$(b).offset().left;
    });    
    console.log(visualOrder);
}

      

Good luck!

+3


source







All Articles