views:

92

answers:

1

How do I take a string and create an html fragment with it in IE. This works fine in non-ie browsers.

var str = "<div>Foo</div>";
var range = document.createRange();
var frag = range.createContextualFragment(str);
var e = document.getElementById("element");
e.appendChild(frag);
+1  A: 

You may want to consider using jQuery? Cross-browser compatible and far easier to use:

$(document).ready(function() {
  var str = "<div>Foo</div>";
  $('#element').append(str); //assuming your element's id is 'element'
});

jQuery site and documentation

KP