Javascript 如果在div中找到值,则按类名更新最近跨度的值

Javascript 如果在div中找到值,则按类名更新最近跨度的值,javascript,jquery,html,Javascript,Jquery,Html,我有一个div,里面有两个span,我正在检查该div中是否已经存在文本,如果已经存在,则更新span中的文本 以下是我所在部门的结构: <div class="top-cart-items"> <div class="top-cart-item clearfix"> <div class="top-cart-item-desc">Orange Club <span class="top-cart-item-price">£2.99</sp

我有一个
div
,里面有两个
span
,我正在检查该
div
中是否已经存在文本,如果已经存在,则更新
span
中的文本

以下是我所在部门的结构:

<div class="top-cart-items">

<div class="top-cart-item clearfix">
<div class="top-cart-item-desc">Orange Club
<span class="top-cart-item-price">£2.99</span>
<span class="top-cart-item-quantity">x1</span>
</div>
</div>

<div class="top-cart-item clearfix">
<div class="top-cart-item-desc">Blue Tang
<span class="top-cart-item-price">£2.99</span>
<span class="top-cart-item-quantity">x1</span>
</div>
</div>

<div class="top-cart-item clearfix">
<div class="top-cart-item-desc">Soft Ball
<span class="top-cart-item-price">£3.99</span>
<span class="top-cart-item-quantity">x1</span>
</div>
</div>

</div>
我也尝试了
sibbines()
find()
,但都没有成功


这里有一个

尝试引入一个map变量来存储添加的新项目,然后您可以:

items[item].find('span.top-cart-item-quantity')
链接:

是的,很完美,我确实这样做了,但我很困惑,我需要添加
返回false
@AbuNooh您必须在哪里添加
返回false
?如果你想粘贴你的解决方案,我不介意看一看并尝试提供帮助。好的,结果是它用
顶购物车商品数量更新了所有类
,我只需要更新最接近的一个。必须删除已接受的答案,但改为向上投票。@AbuNooh是的,你是对的,你需要像这样参考
这个
$(这个)。儿童('span.top cart item quantity')
为你的毅力干杯,字典是一个很好的补充,解决了我的问题,无论如何我都需要在某个时候添加一个数组!接受作为答案如果你想添加链接,那么它可能会帮助其他人。
items[item].find('span.top-cart-item-quantity')