var insertHTML = function(node , html ,where) {
if(node.ownerDocument.createRange) {
var range = node.ownerDocument.createRange();
switch(where) {
case "beforebegin" :
range.setStartBefore(node);
var n = range.createContextualFragment(html);
node.parentNode.insertBefore(n , node);
break;
case "afterbegin" :
range.setStartAfter(node);
if(node.firstChild) {
var n = range.createContextualFragment(html);
node.insertBefore(n , node.firstChild);
} else {
node.innerHTML = html;
}
break;
case "beforeend":
range.setEndBefore(node);
if(node.lastChild) {
var n = range.createContextualFragment(html);
node.appendChild(n);
} else {
node.innerHTML = html;
}
break;
case "afterend" :
range.setEndAfter(node);
var n = range.createContextualFragment(html);
if(node.nextSibling) {
node.parentNode.insertBefore(n , node.nextSibling);
} else {
node.parentNode.appendChild(n);
}
}
} else {
switch(where) {
case "beforebegin" :
node.insertAdjacentHTML("BeforeBegin" , html);
break;
case "afterbegin" :
node.insertAdjacentHTML("AfterBegin" , html);
break;
case "beforeend" :
node.insertAdjacentHTML("BeforeEnd" , html);
break;
case "afterend" :
node.insertAdjacentHTML("AfterEnd" , html);
}
}
};