最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery .find() 2 matching arguments - Stack Overflow

programmeradmin8浏览0评论

I have an unordered list with multiple properties per element and I want to find all elements that have both properties.

var results = $('#mylist').find(function() {
    return
        $(this).attr('data-label') == 'red' &&
        $(this).attr('data-size') == 1;
});

I attached an example in the link below:

/

I have an unordered list with multiple properties per element and I want to find all elements that have both properties.

var results = $('#mylist').find(function() {
    return
        $(this).attr('data-label') == 'red' &&
        $(this).attr('data-size') == 1;
});

I attached an example in the link below:

http://jsfiddle/nbz4H/1/

Share Improve this question edited Jun 5, 2011 at 0:16 Niklas 30k5 gold badges53 silver badges74 bronze badges asked Jun 4, 2011 at 23:18 Chris AbramsChris Abrams 42.6k20 gold badges54 silver badges57 bronze badges 2
  • 1 FYI, find does not accept a function. Maybe you meant filter. – Felix Kling Commented Jun 4, 2011 at 23:25
  • 2 Just a pointer, but if you're using jQuery you should select jQuery from the select drop-down element on the left of the JS Fiddle demo page... – David Thomas Commented Jun 4, 2011 at 23:26
Add a ment  | 

2 Answers 2

Reset to default 9

Just use a single selector:

$('li[data-label="red"][data-size="1"]').css('color','red');

Example: http://jsfiddle/niklasvh/RyR87/

jQuery's find doesn't take a function as a parameter. That's why this doesn't work.

What you need is to construct an appropriate CSS selector. Something like:

 results = $('#mylist [data-label="red"][data-size="1"]');
发布评论

评论列表(0)

  1. 暂无评论