Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8705225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:18:29+00:00 2026-06-13T03:18:29+00:00

My problem is this: I’m submitting a form with a textarea input, which contains

  • 0

My problem is this: I’m submitting a form with a textarea input, which contains an HTML table in the content with specific values in the TD elements which I am trying to parse and add a class to the TD based on that value; then save that back to the form before being sent to the server.

The table looks something like this:

<table>
<tr>
  <td>b</td>
  <td>r</td>
</tr>
<tr>
  <td>y</td>
  <td>n</td>
</tr>
</table>

And here’s the JS I have right now:

$('#form').submit(function() {
  var table = $('#mytextarea').val();

  $('td', table).each(function() {
    var td = $(this);
    switch(td.text()) {
      case 'r':
        td.addClass('red');
        break
      case 'y':
        td.addClass('yellow');
        break
    }
    table = td.wrap('table').parent().html();
  });
});

So essentially I just want to parse HTML inside of a string and add classes to the elements, then save back to the string, if that makes sense.

Here’s a fiddle:

http://jsfiddle.net/Z265d/

I think I’m close but not quite there yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:18:30+00:00Added an answer on June 13, 2026 at 3:18 am

    I wrapped a div around your table, and changed the wrap to closest, which will get the table, then its parent (div), and get its html.

    http://jsfiddle.net/Z265d/3/

    var table = '<div><table><tr><td>r</td><td>y</td></tr><tr><td>g</td><td>b</td></tr></table></div>';
    
    $('td', table).each(function() {
      var td = $(this);
      switch(td.text()) {
        case 'r':
          td.addClass('red');
          break;
        case 'y':
          td.addClass('yellow');
          break;
        case 'b':
          td.addClass('blue');   
          break;
        case 'g':
          td.addClass('green');   
          break;          
      }
      table = td.closest('table').parent().html();
    });
    
    $('#output').text(table);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem this time is to get the median of three values (easy) I
I had a problem this week (which thankfully I've solved in a much better
I have got a strange problem.This is my code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
what is the problem this the next program in Scheme which solve the problem
Good day, I'm stuck with a problem this morning. I found out that content
I have a strange problem.This is my form if User is banned, checkbox is
Problem This question actually came up at work today. We are planning an experiment
Problem : This is a probably a very basic question, but how do I
I'm running in to the same problem this individual has . Specifically, I'm trying
I have this pattern written ^.*\.(?!jpg$|png$).+$ However there is a problem - this pattern

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.