Jquery get element containing child element with specific html value

后端 未结 5 1996
执笔经年
执笔经年 2021-02-19 19:22

I would like to use Jquery to add a class to \"li\" element that contains a \"span\" element with a html/val equal to zero.

For Example if my code looks like this:

5条回答
  •  情歌与酒
    2021-02-19 19:53

    Try:

    $('li span.num').filter(
        function(i){
            return $(this).text() == '0';
        }).closest('li').addClass('selected');
    

    JS Fiddle demo.

提交回复
热议问题