JQuery: displaying elements with a specific title

I am trying to show only those elements that have the title attribute passed to the function:

var selectservice = function(serviceStr) { $j("li.project").hide(); $j("li.project.attr('title').contains(serviceStr)").show(); }; 

I'm not quite sure how to compare the title attribute with the passed serviceStr string? contains does not seem to work.

+4
source share
1 answer

Use the attribute equal to the selector , for example:

 var selectservice = function(serviceStr) { $j("li.project").hide(); $j("li.project[title='" + serviceStr + "']").show(); }; 

Please note that there are other parameters for attributes, and not just equal ones, for example, contains, ends, starts with, etc. See here for a complete list .

+5
source

Source: https://habr.com/ru/post/1305929/


All Articles