danie7L T
danie7L T

Reputation: 384

jQuery to extract HTML content from textbox

I have a function that cleans some attributes out of html tags. I want to add a textbox to insert the HTML source and get it back all cleaned up but I cant find the way to work with the textbox (simply using .val() or .html() doesn't help).

An example:

HTML IN - inserted in the textbox

<tr>
<td nowrap="" valign="top" width="47">
          <p align="center">Out</p>
</td>
    <td nowrap="" valign="top" width="92">
          <p align="right">268.292,00</p>
</td>
</tr>

HTML OUT - on a click event ->this code appears in the textbox (or another one) so I can copy/paste it

<tr>
<td>
          <p>Out</p>
</td>
    <td>
          <p>268.292,00</p>
</td>
</tr>

Many questions talk about textboxes but nothing really gave me the way to go...

Thanks a lot for the help

Upvotes: 1

Views: 156

Answers (1)

Elliott
Elliott

Reputation: 2729

If you are using input type="text", you can use val(), however, if you are using a textarea, you have to use html() as the text inside the box is stored between the opening and closing tags, rather than as a property of the textbox.

You can transfer text from one textbox to another like this:

$(function(){
    $('#textarea2').html($('#textarea1').html());
});

jsFiddle here

Edit: Actually that's rubbish. You can use val()

Upvotes: 1

Related Questions