3

Possible Duplicate:
Remove non breaking space ( ) from between elements using jquery

How to write a script to trim white space/tab between two element?
For example,

<tr>       <td>A     </td>                <td>B   </td>      <td>C    </td>       </tr>

Convert to,

<tr><td>A     </td><td>B   </td><td>C    </td></tr>

For the example, the script should remove the white space/tab between first <td>xxx</td> element and second <td>xxx</td> element and so on.

Thanks

1
  • Why would you need to do this? That white space has no effect on anything. Or do you mean that the code is actually displayed as text on the page? Commented Jul 31, 2011 at 16:30

2 Answers 2

8

Use:

function specialTrim(str){
    return str.replace(/>\s+</g,'><');
}
Sign up to request clarification or add additional context in comments.

Comments

3

You can use contents() with filter() to match the text nodes inside your <tr> element:

$("tr").contents().filter(function() {
    return this.nodeType == 3;
}).remove();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.