Skip to main content
added 37 characters in body
Source Link
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]') // this works > true $('<b>').data('x', 1).is('[data-x=1]') // this doesn't > false $('<b>').attr('data-x', 1).is('[data-x=1]') // attrthis however...is the workaround > true 

CanYou 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 

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 $('<b>').attr('data-x', 1).is('[data-x=1]') // attr however... > true 

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 

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

$('<b data-x="1">' ).is('[data-x=1]') // this works > true $('<b>').data('x', 1).is('[data-x=1]') // this doesn't > false $('<b>').attr('data-x', 1).is('[data-x=1]') // this is the workaround > true 

You 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 
added 80 characters in body
Source Link
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   $('<b>').attr('data-x', 1).is('[data-x=1]') // attr however... > true 

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 

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 

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   $('<b>').attr('data-x', 1).is('[data-x=1]') // attr however... > true 

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 
Source Link
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