prepend/append works in Chrome and Firefox but not IE11 and Edge
Asked Answered
F

4

6

Trying to prepend data inside a text box in Chrome and Firefox works. Get error: SCRIPT438: Object doesn't support property or method 'prepend' in IE11 and Edge. Thx

    function init_TGs(){
        if (confirm("Initialize TinyG's?")){
            $.ajax({
                type: 'POST',
                url: "init_TGs", 
                data: 'None',
                success: function(result){
                    if (result != ''){
                        var rslt= result;
                        var item = document.getElementById('TextArea1');
                        item.prepend(rslt);
                    }}
                });
            }};
Fowlkes answered 23/2, 2018 at 1:30 Comment(0)
E
0

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/prepend#Browser_compatibility Prepend doesn't have support for IE and edge. Instead of Prepend just try to rewrite the business logic with some other function.

Electrostatic answered 23/2, 2018 at 1:35 Comment(0)
H
24

Or, instead of adding a new polyfill you can use insertBefore function which is supported by all browsers:

var rslt= result;
var item = document.getElementById('TextArea1');
item.insertBefore(rslt, item.childNodes[0]);
Hassle answered 19/4, 2019 at 11:44 Comment(0)
A
6

IE and Edge does not support the javascript prepend method, so to make prepend method to work you need to use polyfill.

(function (arr) {
  arr.forEach(function (item) {
    if (item.hasOwnProperty('prepend')) {
      return;
    }
    Object.defineProperty(item, 'prepend', {
      configurable: true,
      enumerable: true,
      writable: true,
      value: function prepend() {
        var argArr = Array.prototype.slice.call(arguments),
          docFrag = document.createDocumentFragment();

        argArr.forEach(function (argItem) {
          var isNode = argItem instanceof Node;
          docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem)));
        });

        this.insertBefore(docFrag, this.firstChild);
      }
    });
  });
})([Element.prototype, Document.prototype, DocumentFragment.prototype]);

usage

document.getElementById("some_id").prepend(Element-you-want-to-prepend)

for more info check

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/prepend#Polyfill

Acetylene answered 29/8, 2018 at 8:25 Comment(0)
E
0

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/prepend#Browser_compatibility Prepend doesn't have support for IE and edge. Instead of Prepend just try to rewrite the business logic with some other function.

Electrostatic answered 23/2, 2018 at 1:35 Comment(0)
F
-3

ok, use jquery. Simple solution:

$(document).ready(function(){
    $('#button-sel').on('click', function(event) {
        var targ = event.target.id;
        //alert("You clicked on: " + targ);
        $.ajax({
            type: 'POST',
            url: targ, 
            data: 'none',
            success: function(result){
                if (result != ''){
                    var rslt= result;
                    $('#TextArea1').prepend(result);
            }}
        });
});})
Fowlkes answered 12/3, 2018 at 0:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.