Results 1 to 7 of 7

Thread: Javascript - replace HTML tags with spaces

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    Javascript - replace HTML tags with spaces

    Hello,
    I need a java script that can replace all the html tags with the white spaces. What will I need to do this. I have tried many codes but non of them really work. So, if you have any solution or a part of code then please do post back. thank you for your help.

  2. #2
    Join Date
    Nov 2009
    Posts
    518

    Re: Javascript - replace HTML tags with spaces

    Hello,
    I think do this you will need to use regular expressions.
    Here is an example showing the same. See if this helps you
    Code:
        function func(str){
                    return str.replace(/^\s+/, '');
                }
                function rt(str) {
                    return str.replace(/\s+$/, '');
                }
                function allt(str) {
                    return str.replace(/^\s+|\s+$/g, '');
                }
    This is not the whole code, but the general syntax which you will need to use in your code.

  3. #3
    Join Date
    Nov 2009
    Posts
    335

    Re: Javascript - replace HTML tags with spaces

    Hello,
    Do achieve this you will need to run the script below in your browser
    Code:
    function strip(html)
    {
       var test = document.createElement("DIV");
       test.innerHTML = html;
       return test.textContent||test.innerText;
    }
    I hope this will help you.

  4. #4
    Join Date
    Nov 2009
    Posts
    518

    Re: Javascript - replace HTML tags with spaces

    Hello,
    I am not sure that this is what you want, just have a look at it
    Code:
    <table id="whitespace  repository" class="lgclsnm" border = "0" >
         <tr>
            <td> whitespace test
            </td>
            <td> block number
            </td>
         </tr>
    </table>
    Then you will have to do this

    Code:
    <table id="whtspc repo" class="lgclsnm" border="0">
    <tr>
    <td>whitespace test
    </td>
    <td>block number
    </td>
    </tr>
    </table>

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: Javascript - replace HTML tags with spaces

    Hello,
    Here is the code which you are looking for, this is just the syntax of the code. You will need to fill your requirements in the code
    Code:
    <html>
    <head><title>Title here</title>
    <style>
    
    <body>
    content of the body here 
    
    <style>
    </head>
    <body marginwidth="0" marginheight="0">
    ...
    Contents
    ...
    </body>
    </html>

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Javascript - replace HTML tags with spaces

    Hello,
    This code can help you
    Code:
    var bdcont = document.getElementsByTagName('body')[0];
    var rslt = appendtxtnds(bdcont);
    
    function appendtxtnds(element) {
        var txt = '';
    
        // Loop through the childnds of the passed in element
        for (var i = 0, len = element.childnds.length; i < len; i++) {
            // Get a reference to the current child
            var nd = element.childnds[i];
            // Append the nd's value if it's a txt nd
            if (nd.ndType == 3) {
                    txt += nd.ndValue;
            }
            // Recurse through the nd's children, if there are any
            if (nd.childnds.length > 0) {
                    appendtxtnds(nd);
            }
        }
        // Return the final rslt
        return txt;
    }

  7. #7
    Join Date
    Nov 2009
    Posts
    583

    Re: Javascript - replace HTML tags with spaces

    Hello,
    Here is an example showing regular expression
    Code:
      function paddlleft(value, chl, nmb) {
                var repl = new replgExp(".{" + nmb + "}$");
                var paddl = "";
                if (!chl) chl = " ";
                do  {
                    paddl += chl;
                }while(paddl.length < nmb);
                replturn repl.exec(paddl + value)[0];
            }
            function paddlright(value, chl, nmb){
                var repl = new replgExp("^.{" + nmb + "}");
                var paddl = "";
                if (!chl) chl = " ";
                do {
                    paddl += chl;
                } while (paddl.length < nmb);
                replturn repl.exec(value + paddl)[0];
            }

Similar Threads

  1. How to replace HTML code using javascript
    By visioneye in forum Software Development
    Replies: 6
    Last Post: 11-05-2010, 11:38 PM
  2. html tags in windows
    By b.venu in forum Operating Systems
    Replies: 1
    Last Post: 17-09-2009, 12:28 PM
  3. About Hidden tags in HTML
    By OmiWalia in forum Software Development
    Replies: 3
    Last Post: 06-08-2009, 10:45 PM
  4. How to give spaces in html ?
    By Beltran in forum Software Development
    Replies: 3
    Last Post: 27-07-2009, 02:59 PM
  5. Replace <br>,</br> tags with <br/> using XSL
    By Dyumani in forum Software Development
    Replies: 3
    Last Post: 06-06-2009, 04:47 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,718,673,189.28836 seconds with 17 queries