SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    converting element object to HTML string?

    after i've built an element, can i convert that element to html?

    the current method i'm thinking is to append this element to a new <Div> and call the Div's innerHTML but it feels rather dirty. is there a better solution?

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's not necessarily dirty. You don't have to append the DIV to anything. You can also use a document fragment:

    Code javascript:
    var frag = document.createDocumentFragment();
    frag.appendChild(stuff);
    var html = frag.innerHTML;
    delete frag; // if you're concerned about leaving things in memory

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heys thanks for the reply. anyways i was wondering do we actually need to explicitly do the delete. is it fine not to include that statement?


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
  •