Jquery get element containing child element with specific html value

后端 未结 5 2004
执笔经年
执笔经年 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 20:02

    Try this.

    $('ul span.num').filter(function(){
        return $(this).text() == "0";
    }).parent().addClass('disabled');
    

    Demo

提交回复
热议问题