Last element in .each() set

后端 未结 3 482
陌清茗
陌清茗 2020-12-02 22:14

I have an issue, where by I am doing a simple form validation, that needs some custom stuff that the validation plugin could not do for me. Basically, I have a name, email a

3条回答
  •  日久生厌
    2020-12-02 22:28

    For future Googlers i've a different approach to check if it's last element. It's similar to last lines in OP question.

    This directly compares elements rather than just checking index numbers.

    $yourset.each(function() {
        var $this = $(this);
        if($this[0] === $yourset.last()[0]) {
            //$this is the last one
        }
    });
    

提交回复
热议问题