Jquery get element containing child element with specific html value

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

    Here's a fast way to to it:

    $('li .num').each(function(){
        if ( $(this).text() == '0') $(this).parent().addClass('disabled');
    }); 
    

    With a jsFiddle example.

提交回复
热议问题