[Solved] – JavaScript – How can we use JQuery .each() backwards ?

How can we use JQuery .each() backwards ?

Asked on October 20, 2018 in Javascript.
Add Comment


  • 4 Answer(s)

    In the .each() backward function is used in jquery mainly for effect on loop over a list backwards.

    $($("li").get().reverse()).each(function() { / ... / });
    
    

     

    Answered on October 20, 2018.
    Add Comment

    I prefer creating a reverse plug-in eg
    The jQuery in which the function reverse is equal to the function of the method(fn)

    jQuery.fn.reverse = function(fn) {
        var i = this.length;
        while(i--) {
            fn.call(this, i, this)
        }
    };
    

    Variable declared for the variable fn variable I declared to length at which this is the object where
    while is made with – to reverse the function as the function is called with this object which reverse with the given value .

    Answered on October 20, 2018.
    Add Comment

    The jQuery in which the function reverse is equal to the function of the method function

    $.each($(collection).get().reverse(), callback func() {});
    
    

    A $ sign to define/access jQuery. For each value the given value for the function of the
    reverse and the call back function the values are made to reverse with the
    Get method of reverse and the call back function

    Answered on October 20, 2018.
    Add Comment

    $($(“li”).get().reverse()).each(function() { /* … */ });

    Answered on February 13, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.