SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Jquery ReplaceWith(), loop needed

    Code JavaScript:
    $("a").val("USD").click(function(){
    $('tr:nth-child(2) > td:nth-child(6)').replaceWith('<td>$6.38/month</td>');
    $('tr:nth-child(3) > td:nth-child(6)').replaceWith('<td>$2.08/month</td>');
    $('tr:nth-child(4) > td:nth-child(6)').replaceWith('<td>$4.99/month</td>');
    $('tr:nth-child(5) > td:nth-child(6)').replaceWith('<td>$14.95/month</td>');
    $('tr:nth-child(6) > td:nth-child(6)').replaceWith('<td>$2.84/month</td>');
    $('tr:nth-child(7) > td:nth-child(6)').replaceWith('<td>$4.99/month</td>');
    $('tr:nth-child(8) > td:nth-child(6)').replaceWith('<td>$12.46/month</td>');
    $('tr:nth-child(9) > td:nth-child(6)').replaceWith('<td>$3.95/month</td>');
    $('tr:nth-child(10) > td:nth-child(6)').replaceWith('<td>$4.30/month</td>');
    $('tr:nth-child(11) > td:nth-child(6)').replaceWith('<td>$3.96/month</td>');
    });
     
    $("a").val("GBP").click(function(){
    $('tr:nth-child(2) > td:nth-child(6)').replaceWith("<td>&pound;4.08/month</td>");
    $('tr:nth-child(3) > td:nth-child(6)').replaceWith("<td>&pound;1.33/month</td>");
    $('tr:nth-child(4) > td:nth-child(6)').replaceWith("<td>&pound;3.19/month</td>");
    $('tr:nth-child(5) > td:nth-child(6)').replaceWith("<td>&pound;9.57/month</td>");
    $('tr:nth-child(6) > td:nth-child(6)').replaceWith("<td>&pound;1.82/month</td>");
    $('tr:nth-child(7) > td:nth-child(6)').replaceWith("<td>&pound;3.19/month</td>");
    $('tr:nth-child(8) > td:nth-child(6)').replaceWith("<td>&pound;7.98/month</td>");
    $('tr:nth-child(9) > td:nth-child(6)').replaceWith("<td>&pound;2.53/month</td>");
    $('tr:nth-child(10) > td:nth-child(6)').replaceWith("<td>&pound;2.75/month</td>");
    $('tr:nth-child(11) > td:nth-child(6)').replaceWith("<td>&pound;2.53/month</td>");
    });

    Screenshot before the click event of GBP
    http://snag.gy/Pp8nb.jpg
    Screenshot after the click event of GBP
    http://snag.gy/LKvzM.jpg

    As you can see although the currency is changing as desired, once it has been changed it can not be changed back, because the jquery is finished i have tried wrapping the code in a function and then calling it just before the end and it didn't work, any input here would be much appreciated

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Could you post a link to a page where I can see this in action?
    Failing that can you post enough code so that I can reproduce this on my own PC?
    I'm sure it won't be too hard to sort out


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •