469,270 Members | 1,784 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

delete new line, tab in html code

I take html code and I want to get it without new line, tab...;

But, It doesn't work.

My code :

<HTML>
<SCRIPT language=javascript>
function transform() {
var html= document.getElementById("corps").innerHTML;
alert(html.replace("[\f\n\r\t\v]*",""))
}
</SCRIPT>
<BODY onload=transform()>
<DIV id="corps">
<P>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa</P>
<P>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<P>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa</P>
<P>
<TABLE>
<TR><TD>
<TABLE>
ppppppppppppppppppppppp
</TABLE>
<P>aaaaaaaaaaaaaaaaaaaaa</P>
</TD></TR>
</TABLE>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<P>aaaaaaaaaaaaaaaaaaaaaaaaaaaa</P>
</DIV>
</BODY>
</HTML>

May 25 '07 #1
1 4289
On May 25, 1:56 pm, louv...@gmail.com wrote:
I take html code and I want to get it without new line, tab...;

But, It doesn't work.

My code :

<HTML>
<SCRIPT language=javascript>
function transform() {
var html= document.getElementById("corps").innerHTML;
alert(html.replace("[\f\n\r\t\v]*",""))}

</SCRIPT>
<BODY onload=transform()>
<DIV id="corps">
<P>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa</P>
<P>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<P>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa</P>
<P>
<TABLE>
<TR><TD>
<TABLE>
ppppppppppppppppppppppp
</TABLE>
<P>aaaaaaaaaaaaaaaaaaaaa</P>
</TD></TR>
</TABLE>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<P>aaaaaaaaaaaaaaaaaaaaaaaaaaaa</P>
</DIV>
</BODY>
</HTML>
You have troubles determining your regular expression. First thing,
the first argument you don't surround with double quotes but with
slashes, and the second thing, you have to add 'g' after the last
slash, which means 'global' (or whatever, anyway it means that you
want to find ALL occurrences and replace them). So, the conclusion:

alert(html.replace(/[\f\n\r\t\v]*/g, ""));

May 25 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Franco Fellico' | last post: by
3 posts views Thread by silver360 | last post: by
9 posts views Thread by Juergen Huber | last post: by
22 posts views Thread by Cylix | last post: by
5 posts views Thread by rn5a | last post: by
12 posts views Thread by yufufi | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.