Reputation: 13
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
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
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