Skip to main content
1 of 3
psycho brm
  • 7.7k
  • 1
  • 46
  • 42

When searching with [data-x=...], watch out, it doesn't work with jQuery.data(..) setter:

$('<b data-x="1">' ).is('[data-x=1]') > true $('<b>').data('x', 1).is('[data-x=1]') > false 

Can use this instead:

$.fn.filterByData = function(prop, val) { return this.filter( function() { return $(this).data(prop)==val; } ); } $('<b>').data('x', 1).filterByData('x', 1).length > 1 
psycho brm
  • 7.7k
  • 1
  • 46
  • 42