Javascript Jquery更改span标签的值 - 来自另一个div的引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6667730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery change value of span tag - reference from another div
提问by Nathaniel Wendt
So my html code is:
所以我的html代码是:
<div class="product-details">
<div class="availability in-stock">
Availability: <span>In stock</span>
</div>
</div>
I would like to use Jquery to change the span value of "in stock". I am somewhat new to Javascript and Jquery, so how would I change that span value without it having an id to reference.
我想使用 Jquery 来更改“有货”的跨度值。我对 Javascript 和 Jquery 有点陌生,所以我如何在没有 id 引用的情况下更改该跨度值。
Many thanks in advance!
提前谢谢了!
回答by citizen conn
回答by Naftali aka Neal
$('.product-details .availability span').text('foo');
回答by Phil
What you are looking for is either the text()
or the html()
like so:
你所寻找的是无论是text()
或html()
像这样:
$('.availability span').html('This is what you want to change it to');
Here is an example: JsFiddle Demo
这是一个例子:JsFiddle Demo