Iterate through table get tags/elements and their values in each row.
in Using jQuery
•
12 years ago
I have now been playing around for hours trying to figure this out. Swore I would not ask for a solution. Now I have a headache, so I am asking...please.
On one HTML Page (From.htm) I have:
-
<table class="Contents Stylize General">
<tr>
<td class="ProductName">
<a href=">Product 1</a>
</td>
<td align="center" class="ItemQuantity">
<span style="padding: 0; margin: 0;"><input type="text" size="2" name="qty[4df7c1555b822]" id="text_qty_4df7c1555b822" class="qtyInput quantityInput" value="1"/></span>
</td>
</tr><tr>
<td class="ProductName">
<a href=">Product 2</a>
</td>
<td align="center" class="ItemQuantity">
<span style="padding: 0; margin: 0;"><input type="text" size="2" name="qty[4df7c1555b823]" id="text_qty_4df7c1555b823" class="qtyInput quantityInput" value="4"/></span>
</td>
</tr>
</table>
In the calling page (index.htm) I have this:
- <script>
function handle(element) {
$(element).each(function() {
var MyHref = TheHref //http://mysite/products/product1.html
var MyHrefInner = TheHrefInner //Product 1
var MyQty = TheQty //The quantity of <input type="text" size="2" name="qty[4df7c1555b822]" id="text_qty_4df7c1555b822" class="qtyInput quantityInput" value="1"/>
});
}$(function(){
var table = $('<table/>');
table.load('From.htm .Contents.Stylize.General', function(){handle(table);});
});
</script>
I somehow, need to get the values as shown in the handle function for each of Products shown in From.htm.
Keep in mind the only thing I know from From.htm is the class names. I have no idea what products are listed or what the input names are. This table is generated by a third party.
Assume that index.htm and From.htm are on the same website.
Thank you so much for your help.
1