Filter element based on .data() key/value

前端 未结 5 1468
庸人自扰
庸人自扰 2020-12-12 13:08

Say I have 4 div elements with class .navlink, which, when clicked, use .data() to set a key called \'selected\', to a value of

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 14:07

    your filter would work, but you need to return true on matching objects in the function passed to the filter for it to grab them.

    var $previous = $('.navlink').filter(function() { 
      return $(this).data("selected") == true 
    });
    

提交回复
热议问题