I have come across the following HTML:
<div class="calculator-section">
<p>
<span class="x"></span>
<span class="amount">30</span>
</p>
<p>
<span class="y"></span>
</p>
</div>
My goal is to extract the number inside the <span>
with the class 'amount' from each calculator-section
based on the span with class 'x'. It's important to note that there could be multiple divs with the class 'calculator-section' and various <p>
elements within those with different spans.
Here's a rough idea of what I'm attempting, even though it's not functional code:
var amount = 0;
$('.calculator-section p').each(function(i, obj) {
if($(this).$('span').className == "x") {
//Assign the value within the <span> with class 'amount' in the same <p> to the 'amount' variable.
}
});
I hope this example clarifies things. Any suggestions?