Posted on

jQuery won’t let you search using a regular selector for data attributes if those data attributes were added using the data function:

jQuery("#something").data("somekey", "someval");
jQuery("#something[data-somekey=someval]"); // does not find it

Instead, define a new function:

jQuery.fn.filterByData = function(prop, val) {
return this.filter(function() {
return jQuery(this).data(prop) == val;

jQuery("#something").filterByData("somekey", "someval"); // finds it

StackOverflow question:

Stackoverflow answer:

Leave a Reply

Your email address will not be published.