The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Targeting table cells for huge data edits

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #167551

    Hi guys,

    I’ve been asked to go through a rather large data set and increasing each price by 30%.

    I was thinking I could just search through the tables, looking for the start of the prices ($) do the math, and copy the finished table back into wordpress.

    Or any other ideas? Ways to get me started?

    That’s the table markup I have to work with.

    Any help would be much appreciated!


    jQuery + regex should do the trick.

    var rx = /\$([0-9]+)/g; // looks for a dollar sign followed by 1 or more digits
      var data = $(this).html();
      if( rx.test(data) ) { // if this TD has a match in it
        $(this).html(data.replace(rx, function(m, c) {
          return '$' + (c*1.3).toFixed(2); // c*1.3 yields some numbers with many decimal places, but toFixed(2) rounds off to just 2

    You could use toFixed(0) if you want to remove any partial dollar amounts.

    Let me know if you have trouble.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.