techiva.blogspot.com
techiva.blogspot.com

Reputation: 1180

Get span price from radio button using jquery

I have span with class .amount, now I want to capture price from the span

 $('.dimension-layer-dimension').click(function() {
   // I am trying with this javascript
   var price4 = $(this).find('radio:checked').data('price')
   $('span.amount').text(price);
   alert(price4);
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<li class="radio">
  <input class="tmcp-field dimension-layer-dimension tm-epo-field tmcp-radio" name="tmcp_radio_9" data-price="" type="radio">
  <label for="tmcp_choice_9_0_17">72*30</label>
  <span class="price tc-price  hidden">
       <span class="amount">1000</span>
  </span>
</li>

Upvotes: 1

Views: 156

Answers (1)

Satpal
Satpal

Reputation: 133403

You should use traverse up to common parent li.radio then use .find() to get the element.

To get the text use .text() and to set .text(newValue)

 $('.dimension-layer-dimension').click(function() {
    var spanEl = $(this).closest('li.radio').find('span.amount');
    var price = spanEl.text(); //Get text
 });

Upvotes: 2

Related Questions