Filter divs by data-attr containing string

前端 未结 4 1231
醉酒成梦
醉酒成梦 2021-01-18 17:21

How to filter a number of divs based on what they have in their custom data attribute using jQuery? The problem is that the attribute can have more than 1 value

4条回答
  •  甜味超标
    2021-01-18 17:48

    Using this css filter element[attr*=partial] will find any element that contains that partial in the attribute

    function filter(e){
    $('.size').hide()
        .filter('[data-sizes*="'+ e +'"]')
        .show(); // show the filtered elements
    }
    

    And its pure css selector, there are more checkout here

提交回复
热议问题