jQuery: Select data attributes that aren't empty?

前端 未结 11 1158
死守一世寂寞
死守一世寂寞 2020-11-30 23:30

I\'m trying to select all elements that have a data-go-to attribute that is not empty.

I\'ve tried $(\'[data-go-to!=\"\"]\') but oddly enou

11条回答
  •  暖寄归人
    2020-11-30 23:53

    I'm not sure about a simple selector, but you could use filter():

    $('[data-go-to]').filter(
        function(){
            return ($(this).attr('data-go-to').length > 0);
        });
    

    JS Fiddle demo.

    References:

    • filter().

提交回复
热议问题