nicoleta
nicoleta

Reputation: 13

How do I get span text value in prototype

This is my prototype code:

$$('coupon-value').findAll("price").innerHTML

<span class="coupon-value"><span class="price">66.67</span></span>

How do I get the value of .price in the prototype? In my html code there are multiple price classes. In jquery it would be simple:

$(".coupon-value").find(".price").text();

But in prototype I have no idea. Can you help me?

Upvotes: 1

Views: 1859

Answers (2)

Leo
Leo

Reputation: 675

Try:

$$('coupon-value').getElementsByClassName("price").innerHTML;

You can change innerHTML for [0]

Like this:

$$('coupon-value .price')[0];

Or even this:

$$('span.price')[0];

Upvotes: 0

Geek Num 88
Geek Num 88

Reputation: 5312

If you would like to get the contents of the <span> with the price class that is a child of a <span> with the coupon-value class you would do it like this

$$('.coupon-value .price').first().innerHTML

This will give you the first element that matches that CSS selector. You can also be very specific with your CSS selection as well.

$$('span.coupon-value span.price').first().innerHTML

you can also select that element and then traverse down the DOM like this

$$('.coupon-value').first().down('.price').innerHTML

Just be aware $$() returns an array of elements that match the CSS selector so you cannot just operate on them like a jQuery collection. However all of the elements in that array are already extended with the PrototypeJS extensions.

Upvotes: 3

Related Questions