javascript - .each() function on affect current object -


having issues code below, first here html:

<table class="finance-table">   <tbody><tr>     <th></th>     <th>deposit</th>     <th>balance</th>     <th>fees</th>     <th>total payable</th>     <th>term</th>     <th>fixed rate</th>     <th>representative apr</th>      <th>monthly pmt</th>    </tr>   <tr class="hp">     <td><strong>hp</strong></td>     <td id="td_finance_deposit">£11700.00</td>     <td id="td_finance_balance">£105300.00</td>     <td id="td_finance_fees">£298.00</td>     <td id="td_finance_total_inc_deposit">£146255.50</td>     <td id="td_finance_term">60 mths</td>     <td id="td_finance_rate">5.50%</td>     <td id="td_finance_apr">10.1%</td>      <td id="td_finance_monthly_payments">£2242.59 p/m*  x 60 mths</td>    </tr> </tbody></table> 

there 10 of these tables [within same document], same id's , class's. i'm using each loop execute code against each table found, seems working on first table , disregards others.

below jquery, said works find on first table, ignores rest!

<!-- remove first , final payment showroom finance examples --> <script>   $(".finance-table").each(function(key, value) {     // display loading     var html = $(this);      // remove first payment , final payment column     $(this).find("#td_finance_first_payment, #td_finance_final_payment").remove();     $(this).find("th:contains('1st pmt')").remove(); $(this).find("th:contains('final pmt')").remove();      // term , update monthly payment     var term = $(this).find("#td_finance_term").html(); // .replace(/\d/g,'')     var payments = ($(this).find("#td_finance_monthly_payments").html()).split('x')[0];     ($(this).find("#td_finance_monthly_payments")).html(payments + " x " + term);   }) </script> 

edit: please note, can't change html @ all

you should first give unique id each <td>, perhaps db identifier record. don't need allow other thing later if need it.

then change <td> ids classes:

<td class="td_finance_fees">£298.00</td> 

finally change javascript accordingly use class instead of ids:

$(this).find(".td_finance_first_payment, .td_finance_final_payment").remove(); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -