Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selectors wildcard where not

Trying to figure out how to apply a wildcard concept to something while applying where not.

Right now I have $('.zm_name[rel!="'+keyed+'"]').parent().hide(); which will hide everything not exactly matching the keyed value I am looking for, this works fine. However it only works when the keyed value is exact. So I am looking to have it so its like keyed* but anything not equal to the beginning of the string hide.

I tried $('.zm_name[rel^!="'+keyed+'"]').parent().hide(); but only get a syntax error, I browsed through the jquery selectors section of the api, and can't seem to find what I am looking for exactly. So I am wondering is there any actual way of combining this method?

like image 297
chris Avatar asked Dec 06 '25 13:12

chris


2 Answers

Try this

$('.zm_name:not(.zm_name[rel^="'+keyed+'"])').parent().hide();

//OR

$('.zm_name:not([rel^="'+keyed+'"])').parent().hide();​​​​​​​

DEMO

like image 83
Sushanth -- Avatar answered Dec 08 '25 22:12

Sushanth --


I usually stay away from very long selectors because they can be confusing and redundant. Try using the filter method:

$('.zm_name').filter(function(){ 
  return !(new RegExp('^'+ keyed)).test(this.rel); 
});
like image 23
elclanrs Avatar answered Dec 09 '25 00:12

elclanrs