jquery - Find element where any attribute equals something -


what need :

 jquery("a[anyattributename='something']"); 

i know how regular javascript...

question:

is there way using jquery selectors?

for example: have elements a[href='value'], b[title='value'], c[src='value'].

i want using 1 jquery selector find elements of attributes has value...

i don't wanna that
$("a[href='value'], b[title='value'], c[scr='value']") because have 1k elements.

you can use filter want:

$('a').filter(function(){     for(var = 0, l = this.attributes.length; < l; i++)         if(this.attributes[i].nodevalue === 'something')             return this; }); 

to use selector, need create :

jquery.extend(jquery.expr[':'], {      value: function(a, _, v) {          for(var = 0, l = a.attributes.length; < l; i++)             if(a.attributes[i].nodevalue === v[3])                 return true;         return false;     } })  

then use :

$('div:value(test)'); 

http://jsfiddle.net/55bz3/


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -