0

I'm using DocumentFragment to append some child nodes into list, but I'm facing nonsupporting problems in some browsers. So I wanted to know is there another way of checking that besides the method of checking if browser is in the list of supported browsers (or at least a method that do this job for me)?

Sorry!!! Here is the code that I'm using

var frag = document.createDocumentFragment();
var li = document.createElement('li');
    li.className = "folders items";
    li.innerHTML = '<a href="'+ f.id +'" title="'+ f.name +'" class="folders">'+icon+'<span class="name">' + name + '</span><span class="details">' + itemsLength + '<span class="desc '+nrMg+'">' + itemsDesc + '</span></span></a>';
    frag.append(li);
container.append(frag);

container is Jquery object ($('#listF'))

Solved: My mistake, I was using append() which seems to work in chrome, but not in other browsers. The right method to append element on documentFragment is appendChild().

Working code:

var frag = document.createDocumentFragment();
var li = document.createElement('li');
    li.className = "folders items";
    li.innerHTML = '<a href="'+ f.id +'" title="'+ f.name +'" class="folders">'+icon+'<span class="name">' + name + '</span><span class="details">' + itemsLength + '<span class="desc '+nrMg+'">' + itemsDesc + '</span></span></a>';
    frag.appendChild(li);
container.append(frag);
Mr. Nobody
  • 340
  • 3
  • 17
  • 2
    Why not just use `document.createDocumentFragment`? –  Jan 22 '17 at 13:52
  • 2
    Please add the code that depends on `DocumentFragment` to see what the dependencies are. – trincot Jan 22 '17 at 13:59
  • 1
    what? non supporting? http://ejohn.org/blog/dom-documentfragments/ `it’s part of the DOM 1 specification and is supported in all modern browsers (it was added to Internet Explorer in version 6)` – num8er Jan 22 '17 at 14:02
  • I visited this page a couple hours ago, and I didn't noticed what was the problem. Now that i visited again, double checked and problem solved. Thank you. – Mr. Nobody Jan 22 '17 at 16:08
  • 1
    @num8er The issue here is (maybe?) the support for the constructor form `new DocumentFragment`. Document fragments themselves, and `document.createDocumentFragment`, have perfectly good support. –  Jan 22 '17 at 17:05
  • Don't add a solution inside the question. –  Jan 22 '17 at 17:07

0 Answers0