开发者

JQuery: showing elements with a particular title

开发者 https://www.devze.com 2022-12-25 18:58 出处:网络
I am trying to show only elements that have the title attribute passed to开发者_JAVA技巧 the function:

I am trying to show only elements that have the title attribute passed to开发者_JAVA技巧 the function:

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

I am not quite sure how to compare the title attribute to the passed string serviceStr? contains doesnt seem to work.


Use the attribute equals selector, like this:

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

Note that there are other options for attributes as well, not just equals, like contains, ends with, starts with, etc. See here for a full list.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号