开发者

Jquery change value of span tag - reference from another div

开发者 https://www.devze.com 2023-03-19 23:53 出处:网络
So my html code is: <div class=\"product-details\"> <div class=\"availability in-stock\"> Availability: <span>In stock</span>

So my html code is:

<div class="product-details">
    <div class="availability in-stock">
          Availability: <span>In stock</span>
    </div>
</div>

I would like to use Jqu开发者_开发问答ery 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.

Many thanks in advance!


$('.in-stock span').html("your new string");

http://jsfiddle.net/hQqtU/


$('.product-details .availability span').text('foo');

Fiddle: http://jsfiddle.net/maniator/EryVF/


What you are looking for is either the text() or the html() like so:

$('.availability span').html('This is what you want to change it to');

Here is an example: JsFiddle Demo

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号