Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: How to clear the contents of the div tag ?

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
Share This Thread →
  1. #1
    rajesh466 is offline Registered User
    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
    rajesh466 is offline Registered User
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0
    Quote 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 = "";

  3. #3
    Guddu's Avatar
    Guddu is offline Contributing User
    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 !!!!!!!!

  4. #4
    Shadow Wizard's Avatar
    Shadow Wizard is offline Moderator From Beyond
    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";

  5. #5
    ChiefWigs1982's Avatar
    ChiefWigs1982 is offline Cunning Linguist
    Join Date
    Mar 2005
    Location
    I used to live at home, now I stay at the house
    Posts
    3,580
    Rep Power
    429
    Quote 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!


  6. #6
    Shadow Wizard's Avatar
    Shadow Wizard is offline Moderator From Beyond
    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,126
    Rep Power
    2921
    Quote 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.

  7. #7
    ChiefWigs1982's Avatar
    ChiefWigs1982 is offline Cunning Linguist
    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().

  8. #8
    rajesh466 is offline Registered User
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0
    Quote 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() ?

  9. #9
    ChiefWigs1982's Avatar
    ChiefWigs1982 is offline Cunning Linguist
    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

  10. #10
    nivs1978 is offline Registered User
    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...

    Quote Originally Posted by Shadow Wizard
    better practice would be to simply hide it:
    Code:
    document.getElementById('divStatus').style.display = "none";

  11. #11
    Shadow Wizard's Avatar
    Shadow Wizard is offline Moderator From Beyond
    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,126
    Rep Power
    2921
    Quote 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.

  12. #12
    btheoret is offline Registered User
    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:

    Quote 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.

  13. #13
    Shadow Wizard's Avatar
    Shadow Wizard is offline Moderator From Beyond
    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,126
    Rep Power
    2921
    Quote 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 = "";

  14. #14
    annaharris is offline Registered User
    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("""");

  15. #15
    bparker1084 is offline Registered User
    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 LastLast
Share This Thread →

Become Part of This Conversation

Join NowFor Free!

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

ASP Free Advertisers and Affiliates