MJ
asked on
Capture Duplicate Class Name Text and Clean Up Currency, if Present?
How to get multiple values from N # of same class name? In the example below I want to grab the text whenever there is a class name of "offer-product-label" and divide with a pipe. If there is a currency amount, strip to only dollar amount. So the below example would return => "Line of Credit|450000"
I started with:
Thanks!
I started with:
var pResult;
var prodResult = document.getElementsByClassName("offer-product-label");
for (var i = 0; i < prodResult.length; i++) {
pResult = prodResult[i].innerText;
}
for the below:<fieldset class="fieldset-line">
<legend tabindex="0">Request summary</legend>
<dl tabindex="0">
<dt>Product</dt>
<dd class="offer-product-label">Line of Credit</dd>
</dl>
<dl tabindex="0">
<dt>Amount Requested</dt>
<dd class="offer-product-label">$45,000.00</dd>
</dl>
</fieldset>
Thanks!
ASKER
Hi Again Leakim,
Thanks again for all your help! What about the part of cleaning up the currency?
Thanks again for all your help! What about the part of cleaning up the currency?
replace :
pResult.push(prodResult[i].innerText.replace)
by :var str = prodResult[ i ].innerText;
pResult.push( /(?=.*\d)^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?(\.\d{1,2})?$/.test(str) ? Number(str.replace(/[^0-9.-]+/g,"")) : str );
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I'm forever indebted to you! I will give you my 1st born! :0)
Open in new window