Filtering for specific attribute of a child

时间:2018-03-25 19:42:15

标签: jquery filter

I'm trying to find a child with this exact background color in a nav_list ul.

All <li> items are created dynamically; the alert() gives me undefined, what am I doing wrong?

var matching = $('.nav_list li').filter(function(){
                  return $(this).attr('background-color') == "rgb(72, 76, 111)"
               });
alert(matching.attr("class"));

1 个答案:

答案 0 :(得分:0)

我最终使用.addClass("selected")来标记用户点击的<li>