SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    529
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Clearing the contents of a tag in IE

    I have a span tag that I use to dynamically populate with HTML elements and on occasion clear.

    When I want to clear the contents of the span, this works as expected in Firefox:
    Code JavaScript:
    document.getElementById('mySpan').innerHTML = '';

    But this does nothing in IE. What's the best way to clear out the HTML elements in a tag in IE?

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,066
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    That's weird. I know innerHTML is a bit quirky in IE, but I would have thought that would have worked.
    What version of IE are you using?

    To answer your question:

    With jQuery:

    Code:
    $('#mySpan').empty();
    With vanilla JS:

    Code:
    var node = document.getElementById('mySpan');
    while (node.hasChildNodes()) {
        node.removeChild(node.firstChild);
    }

  3. #3
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    529
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! The while loop did the trick.


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
  •