Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    jquery-delete everything inside div, but not the div

    I have one simple question. How to delete everything inside div?
    I know how to delete it together with div
    Code:
    $("#test").remove();
    but I don't looking for that because I want that <div id="test"></div> stay there.

    Thank you

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    $("#test").children().remove();

    ?

  • #3
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    You could also possibly use.
    Code:
    $('#test > *').remove();
    Not sure which is faster though.

    Or alternatively..
    Code:
    $('#test').html('');

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could use prototype, test for child first to prevent error...
    if($('yourdiv).down){
    $('yourdiv).down.remove()
    }
    iterate to remove all children.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •