javascript - Is it possible to select element by attribute value only? -
i need find elements in page attribute value
(ignoring key) using jquery.
is there way easily?
currently, iterating on elements in page, on every property etc..
you can use $.expr
, element.attributes
, array.prototype.some()
$.expr[":"].attrvalue = function(el, idx, selector) { return [].some.call(el.attributes, function(attr) { return attr.value === selector[selector.length - 1] }) }; // filter element having attribute `value` set `"abc"` $(":attrvalue(abc)").css("color", "blue");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script> <div title="abc">abc</div> <div title="def">def</div> <div title="ghi">ghi</div> <div title="jkl">jkl</div>
Comments
Post a Comment