jquery get all elements matching data attribute name jquery get all elements matching data attribute name jquery jquery

jquery get all elements matching data attribute name


You can use the attribute selector:

$('[data-my-key]').click(...

Note however, that jQuery stores data attributes added after DOM load in it's internal cache not as an attribute on the element, so that selector would not work for those. In that case you would need to use filter:

$(document).children().filter(function() {    return $(this).data('my-key');}).click(...;


You can use has attribute selector and give the attribute name.

$('[data-my-key]').click...