Jquery get element containing child element with specific html value

后端 未结 5 1995
执笔经年
执笔经年 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

    You can match the element with filter(), then get its parent

    with parent():

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

提交回复
热议问题