I am trying to modify the plugin livefilter for jquery. I need it to search the title tag of an an LI as well as its contents. I have already modified it slightly (@ line #32) so that it does not hide matches, instead it will bold them as well as change the background to all matches.
I tried modifying the following lines:
/** Case insensitive :contains jQuery pseudo selector */
$.expr[":"].icontains = function(obj, index, meta, stack) {
return (obj.textContent || obj.innerText || jQuery(obj).text() || "").toLowerCase().indexOf(meta[3].toLowerCase()) >= 0;
};
adding this to the returned statement:
|| jQuery(obj).attr('title')
But this does not seem to work…
Be aware than because of OR operator
||, the test stops as soon one of the part is true, the other “parts” will not be tested at all (hopefully I’m clear).This kind of writing is typically used because of the differences between browser’s implementations, that might or not have such properties.
This is the case in the following context:
textContentis not supported under IE<9, soobj.textContentwill be evaluated as false, theninnerTextwill be evaluated and so on. The last|| ""ensures a string is finally returned so the code does not break.Another use of this kind of syntax is to ensures an object is defined, like this:
Further reading:
What you want is the content and the title attribute, so try this:
DEMO