You can use a custom pseudo selector to filter by attribute.
The following is a jQuery method.
$.expr[":"].attrFilter = function(elem, index, val){ var len = $(elem.attributes).filter(function () { return this.value === val[3]; }).length; if (len > 0) { return elem; } }; $('body *:attrFilter("value")').hide();
Demo Screenshot
$.expr[":"].attrFilter , is an extension mechanism for custom selectors. You can also pass a parameter.
Syntax :
$.expr[':'].selector = function(elem, index, match) { }
Shaunak d
source share