I need to extract a sub string, particularly "Sweet Heart" Package (SPA02) from this string:
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Find String</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = '<div class="view view-commerce-line-item-table view-id-commerce_line_item_table view-display-id-default view-dom-id-57765ff55f834d6a7ec1b8f510768a90">
<div class="view-content">
<table class="views-table cols-4"><thead><tr><th class="views-field views-field-line-item-title">
Title </th>
<th class="views-field views-field-commerce-unit-price">
Unit price </th>
<th class="views-field views-field-quantity">
Quantity </th>
<th class="views-field views-field-commerce-total views-align-right">
Total </th>
</tr></thead><tbody><tr class="odd views-row-first views-row-last"><td class="views-field views-field-line-item-title">
"Sweet Heart" Package (SPA02) </td>
<td class="views-field views-field-commerce-unit-price">
135.00 CAD </td>
<td class="views-field views-field-quantity">
1 </td>
<td class="views-field views-field-commerce-total views-align-right">
135.00 CAD </td>
</tr></tbody></table></div>
</div>';
var n = str.indexOf('class="odd views-row-first views-row-last"><td class="views-field views-field-line-item-title">');
document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>
I have tried this to find the beginning of the string:
str.indexOf('class="odd views-row-first views-row-last"><td class="views-field views-field-line-item-title">');
but it doesn't return a valid integer position, it in fact doesn't return anything... and I'm wondering what I'm doing wrong and how i'd best go about this.
Thanks!