1

I'm trying to grab an element's HTML using jQuery and then post it to the server. I successfully grabbed it, but I am not able to remove the white space between the tags and the line breaks that are rendered by default. The HTML code grabbed is shown below:

<table><tbody><tr><th></th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th></tr>
                <tr><th>2nd row</th><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table>

I would like to trim the spaces between the tags only. I've used this regular expression: str.replace(/\s+/g, ' ');. But that doesn't seem to work, any suggestions?

2 Answers 2

3

Currently, you are replacing all consecutive sequences of whitespace with a single space.

This is what you want:

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

2 Comments

First of all, thanks for your help. But, it doesn't work. i.sstatic.net/VfkXe.png
the string also contain some line breaks not only spaces.
0

I need to add escape character(backslash - ) character at the end of each line to wrap the string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.