delete new line, tab in html code

L

louvino

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>
 
D

Darko

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, ""));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top