Page 231 - Web_Application_v2.0_C12_Fb
P. 231

document.getElementById("demo1").innerHTML = text1.concat(" ", text2);
                    </SCRIPT>

                    </BODY>
                    </HTML>
                 Output:

















                 9.  The trim() Method: The trim() method removes whitespace from both sides of a string.

                 Example 39: To demonstrate the use of trim method

                    <!DOCTYPE HTML>
                    <HTML>
                    <HEAD>
                    <TITLE>trim() Method</TITLE>
                    </HEAD>

                    <BODY>
                    <H2>The trim() Method</H2>
                    <P>The trim() method removes whitespace from a string.</P>
                    <P id="demo1"></P>

                    <SCRIPT>
                    var text = "   Hello World   ";
                    document.getElementById("demo1").innerHTML = text.trim();
                    </SCRIPT>

                    </BODY>
                    </HTML>
                 Output:




















                                                                                                  JavaScript Part 2  229
   226   227   228   229   230   231   232   233   234   235   236