Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    How to clear the contents of the div tag ?


    I am having the div tag say,
    <div id='divtext'>
    <b> there is some text here </b>
    </div>

    How to clear the contents of the div tag dynamically ?
  2. #2
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0
    Originally Posted by rajesh466
    I am having the div tag say,
    <div id='divtext'>
    <b> there is some text here </b>
    </div>

    How to clear the contents of the div tag dynamically ?
    I got it by using document.getElementById('divStatus').innerHTML = "";
  4. #3
  5. Contributing User
    ASP High Scholar (3500 - 3999 posts)

    Join Date
    Jul 2005
    Location
    Oxford UK
    Posts
    3,897
    Rep Power
    988
    welcome to this forum and Thanks for sharing solution here.

    cheers!!
    Nothing is Impossible bcoz IMPOSSIBLE itself says..
    I M POSSIBLE........................
    Be cool !!!!!!!!
  6. #4
  7. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,126
    Rep Power
    2921
    better practice would be to simply hide it:
    Code:
    document.getElementById('divStatus').style.display = "none";
  8. #5
  9. Cunning Linguist
    ASP High Scholar (3500 - 3999 posts)

    Join Date
    Mar 2005
    Location
    I used to live at home, now I stay at the house
    Posts
    3,580
    Rep Power
    429
    Originally Posted by Shadow Wizard
    better practice would be to simply hide it:
    Code:
    document.getElementById('divStatus').style.display = "none";
    Why's that better practice?
    Support requests via PM will be ignored!
    Route of Queue | The General FAQ Thread | HOW TO POST A QUESTION

    Perfectly Impossible - is the eagerly awaited debut release from Jayne Sarah - please buy it - it's really good!

  10. #6
  11. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,126
    Rep Power
    2921
    Originally Posted by ChiefWigs1982
    Why's that better practice?
    when assigning empty HTML all the children are removed - some parsing
    is needed. hiding the contents requires no parsing and achieve the
    same goal, as far as I can tell.
  12. #7
  13. Cunning Linguist
    ASP High Scholar (3500 - 3999 posts)

    Join Date
    Mar 2005
    Location
    I used to live at home, now I stay at the house
    Posts
    3,580
    Rep Power
    429
    I think it's a different thing all together - it doesn't achive the
    same thing!

    You're right though, the solution provided is not the best one.
    It would be best to remove the contents of the div with DOM
    methods like removeChild().
  14. #8
  15. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0
    Originally Posted by ChiefWigs1982
    I think it's a different thing all together - it doesn't achive the
    same thing!

    You're right though, the solution provided is not the best one.
    It would be best to remove the contents of the div with DOM
    methods like removeChild().
    Is it a better practice to remove all the text content using removeChild() ?
  16. #9
  17. Cunning Linguist
    ASP High Scholar (3500 - 3999 posts)

    Join Date
    Mar 2005
    Location
    I used to live at home, now I stay at the house
    Posts
    3,580
    Rep Power
    429
    Yes, but you're not just removing text, you are removing HTML tags
    as well.

    http://raibledesigns.com/rd/entry/ja...ovechild_howto
  18. #10
  19. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0
    I know this post is old, but how can you from his simple question judge what is best practice?
    Like if he needs to clear the contents to fill in some new, hiding the div is not a very good solution.
    I do not know why so many people in newsgroups give completely irrelevant answers to simple questions. It's a waste of other peopls time.

    Regards Hans...

    Originally Posted by Shadow Wizard
    better practice would be to simply hide it:
    Code:
    document.getElementById('divStatus').style.display = "none";
  20. #11
  21. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,126
    Rep Power
    2921
    Originally Posted by nivs1978
    I know this post is old, but how can you from his simple question judge what is best practice?
    Like if he needs to clear the contents to fill in some new, hiding the div is not a very good solution.
    I do not know why so many people in newsgroups give completely irrelevant answers to simple questions. It's a waste of other peopls time.

    Regards Hans...
    I don't judge anything. I say what I believe is better practice, one can
    take it or leave it.
    good luck and thanks for sharing your opinion, Hans.
  22. #12
  23. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Trying to clear the contents of a DIV after I've opened it in a popup


    What I'm trying to do is clear the contents of a DIV after I've opened it in a popup. You mentioned the following:

    Originally Posted by rajesh466
    I got it by using document.getElementById('divStatus').innerHTML = "";
    I'm just trying to figure out where I should put that.
  24. #13
  25. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,126
    Rep Power
    2921
    Originally Posted by btheoret
    What I'm trying to do is clear the contents of a DIV after I've opened it in a popup. You mentioned the following:



    I'm just trying to figure out where I should put that.
    Something like this:
    Code:
    var win = window.open("popup.html", "_blank");
    win.document.getElementById('divStatus').innerHTML = "";
  26. #14
  27. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Mar 2012
    Location
    USA
    Posts
    76
    Rep Power
    0
    To clear the contents of the div tag uou can use the empty() method:
    $(""#yourDivId"").empty();
    Or you can pass an empty string to the html() method:
    $(""#yourDivId"").html("""");

    Comments on this post

    • Shadow Wizard disagrees : No need for jQuery to achieve such trivial task.
  28. #15
  29. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Location
    San Jose
    Posts
    7
    Rep Power
    0
    This should work document.getElementById("level3").innerHTML = ''; but, try thinking about using jQuery, because .innerHTML implementation differs in some browsers. jQuery would look like $('#level3').html('');
Page 1 of 2 12 Last
  • Jump to page:

Similar Threads

  1. Runtime error when trying to clear an unbound cbo after update
    By repeater75 in forum Microsoft Access Help
    Replies: 3
    Last Post: December 15th, 2004, 06:00 PM
  2. Help clearing chat contents
    By mtarby in forum Code Bank
    Replies: 0
    Last Post: August 16th, 2004, 12:41 PM
  3. how to clear contents of a textbox?
    By bubbagump in forum ASP Development
    Replies: 1
    Last Post: February 12th, 2004, 09:10 AM
  4. Keeping Array Contents alive accross Functions
    By Monkey in forum Visual Basic Programming
    Replies: 2
    Last Post: January 30th, 2004, 12:51 PM
  5. using javascript how to clear the options in select list ?
    By Steve Schofield in forum ASP Development
    Replies: 0
    Last Post: January 2nd, 2001, 06:52 AM

IMN logo majestic logo threadwatch logo seochat tools logo