Good day. Tell the script to replace the data in the table ie. I want to do so that by pressing the Russian ruble or another currency, the price in the table with the price list changes:

<table> <tbody> <tr> <th><span style="font-family: arial,helvetica,sans-serif;">Тип программы</span></th> <th><span style="font-family: arial,helvetica,sans-serif;"><strong>с 01.04 по 31.05.2016 </strong></span></th> <th><span style="font-family: arial,helvetica,sans-serif;"><strong>с 01.06 по 30.09.2016 </strong></span></th> </tr> <tr> <td><a href="#">Программа 1</a></td> <td><span style="font-family: arial,helvetica,sans-serif;">2350 RUB за день</span></td> <td><span style="font-family: arial,helvetica,sans-serif;">2540 RUB за день</span></td> </tr> <tr> <td><a href="#">Программа 2</a></td> <td><span style="font-family: arial,helvetica,sans-serif;">2150 RUB за день</span></td> <td><span style="font-family: arial,helvetica,sans-serif;">2350 RUB за день</span></td> </tr> </tbody> </table> 

    2 answers 2

    I hope I understand the question correctly. Well, don `t know the currency rate, but you need to take it or fix it from somewhere ... Good luck.

     jQuery(function($) { var courseUSD = 65; //текущий курс RUB к USD (просто цифра понравилась) $('button[name="changeprice"]').on({ 'click': function changePrice(e) { $(e.currentTarget).toggleClass('USD'); $('.price').each(function(i, item) { $(item).text($(e.currentTarget) .hasClass('USD') ? ($(item).data().priceRub / courseUSD).toFixed(2) + ' USD' : $(item).data().priceRub + ' RUB'); }); } }); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table> <tbody> <tr> <th><span style="font-family: arial,helvetica,sans-serif;">Тип программы</span> </th> <th><span style="font-family: arial,helvetica,sans-serif;"><strong>с 01.04 по 31.05.2016 </strong></span> </th> <th><span style="font-family: arial,helvetica,sans-serif;"><strong>с 01.06 по 30.09.2016 </strong></span> </th> </tr> <tr> <td><a href="#">Программа 1</a> </td> <td><span style="font-family: arial,helvetica,sans-serif;"><span class="price" data-price-rub="2350">2350 RUB</span> за день</span> </td> <td><span style="font-family: arial,helvetica,sans-serif;"><span class="price" data-price-rub="2540">2540 RUB</span> за день</span> </td> </tr> <tr> <td><a href="#">Программа 2</a> </td> <td><span style="font-family: arial,helvetica,sans-serif;"><span class="price" data-price-rub="2150">2150 RUB</span> за день</span> </td> <td><span style="font-family: arial,helvetica,sans-serif;"><span class="price" data-price-rub="2350">2350 RUB</span> за день</span> </td> </tr> </tbody> </table> <button name="changeprice">Change Price USD/RUB</button> 

    • Thank you, now I understand how to formulate a question correctly. I a little bit wrong did it. I want the numbers to connect to ask yourself. - Roman
    • Well, the question was not such a statement of the problem, so I set the course and recalculated hung in the function. But if it is possible to specify by a fix in the data which figures need to be substituted, then this simplifies. - Bear GRiZZLY Xi

    Added here

     jQuery(function($) { $('button[name="changeprice"]').on({ 'click': function changePrice(e) { $(e.currentTarget).toggleClass('USD'); $('.price').each(function(i, item) { $(item).text($(e.currentTarget) .hasClass('USD') ? $(item).data().priceUsd + ' USD' : $(item).data().priceRub + ' RUB'); }); } }); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table> <tr> <td><span style="font-family: arial,helvetica,sans-serif;"><span class="price" data-price-rub="2350" data-price-usd="35">2350 RUB</span> за день</span> </td> </tr> </table> <button name="changeprice">Change Price USD/RUB</button> 

    I edited the correct code? Or should it be simplified?

    • Yes, this option is normal. - Bear GRiZZLY Xi