使用jQuery更新文本匹配上的HTML容器文本

Xep*_*tor 0 javascript jquery

我正在尝试更改缺货产品的文字.这是我到目前为止:

$( ".box.stock:contains('0 Stock')" ).text('Temporarily out of stock. Call to order. ').addClass( "Lager" );
Run Code Online (Sandbox Code Playgroud)

这可行,但它也适用于所有产品零.如何将其更改为只有"0"的库存状态?

epa*_*llo 5

你不能用contains来做到这一点.你需要使用过滤器

$(".box.stock").filter( function() {  
    return $(this).text() === "0 Stock";
}).text('Temporarily out of stock. Call to order. ').addClass( "Lager" )
Run Code Online (Sandbox Code Playgroud)