Check if element is before or after another element in jQuery

后端 未结 9 1575
花落未央
花落未央 2020-12-23 16:23

Let us suppose I have this markup

First

Hi

Hello

Second

9条回答
  •  既然无缘
    2020-12-23 17:07

    Keeping in mind Rocket's answer I prefer to use .index() approach like following:

    $.fn.isAfter = function(sel){
        return $(this).index() > $(sel).index();
    };
    $.fn.isBefore= function(sel){
        return $(this).index() < $(sel).index();
    };
    

    It seems more clear for reading/understanding and works perfectly in rows selection.

提交回复
热议问题