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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -