jQuery Object array notation

后端 未结 2 1132
忘掉有多难
忘掉有多难 2020-12-03 15:55

I\'m new to jQuery, and I\'m having a little trouble understanding its array notation for objects. Reading the jQuery docs and this article, it seems that you can refer to t

2条回答
  •  [愿得一人]
    2020-12-03 16:08

    When you reference a jQuery object as an array you get a DOM element back. You'll need to convert it back to a jQuery object to use methods like .hide()

    var bar = $('.foo')[n];
    var $bar = $(bar);
    
    $bar.hide();
    

    Or just use jQuery's eq() method:

    var bar = $('.foo').eq(n);
    bar.hide();
    

提交回复
热议问题