Skip to content
Advertisement

jQuery: Select data attributes that aren’t empty?

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 enough it seems to be selecting every single element on the page if I do that.

Advertisement

Answer

try

$(':not([data-go-to=""])')

UPDATE:

For the sake of not leading anyone astray, this answer will work in older versions of jQuery but is not future-proof. Since @gmo and @siva’s answers both seem to be working with later versions I defer to (and encourage you to upvote) their answers….and of course hope you have a fantastic day.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement