JQuery selector using value, but unknown attribute
You can use a custom pseudo-selector to filter over the attributes.
Following is a jQuery way.
$.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();
Fiddle Demo
The $.expr[":"].attrFilter
, is an extension mechanism for custom selectors. You can also pass a parameter.
Syntax :
$.expr[':'].selector = function(elem, index, match) {
}
elem
is the current DOM elementindex
is the index of elemmatch
is an array that contains all information about the custom selector,where the parameter passed lies at 3rd index. (Reference 1,Reference 2)match[0]
– contains the full pseudo-class selector call. In this example :attrFilter("value")
match[1]
– contains the selector name only. In this exampleattrFilter
match[2]
– denotes which, if any, type of quotes are used in the parameter - expression. i.e. single (‘) or double (“). In this example it will be empty.match[3]
– gives us the parameters, i.e. what is contained in the brackets. In this example `value