SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member nacker4it's Avatar
    Join Date
    Mar 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove html code line using document.body.innerHTML.replace

    I am replacing a string with another but javascript doesn't work, I am not sure what i did wrong with it?

    My HTML Code is this

    HTML Code:
    
    

    and Java script Code is this:
    HTML Code:
    <script language="javascript">
    document.body.innerHTML = document.body.innerHTML.replace('Hello Worlds', '');
    document.body.innerHTML = document.body.innerHTML.replace('<input type="checkbox" name="Usecheck" value="1"><Strong>Click here</Strong>', '');
    document.body.innerHTML = document.body.innerHTML.replace('<img src="images/button.gif" bordor=0>', '');
    </script>

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nacker4it View Post
    I am replacing a string with another but javascript doesn't work, I am not sure what i did wrong with it?
    Is your script by any chance inside the body of the document?
    Either way you should use DOM methods to remove elements.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The innerHTML does not return literal source code.
    use an alert to show you what the innerHTML looks like-
    it won't match the string you are replacing.

    This will be true, no matter how many times you post the same question.

  4. #4
    SitePoint Member nacker4it's Avatar
    Join Date
    Mar 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No,

    I believe someone good in javascript can solve issue from this code.

    My HTML code is below.
    <HTML>
    Hello Worlds
    <table>
    <tr><td>
    <input type="checkbox" name="Usecheck" value="1"><Strong>Click here</Strong></td><td>
    <img src="images/button.gif" bordor=0>
    <td></tr>
    </table>
    </HTML>

    First line of code "Hello Worlds" successfully hide when page load but image and checkbox are not.

    Is there any good javascript guru there who solve this issue?


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
  •