Search code examples
javascriptdombrowseropera

DOM's native append function not available in Opera neon


We have a lot of tracking scripts installed on our web app and we install them by appending onto head/body section using same old JS snippent

document.getElementsByTagName('body')[0].append(scriptObject);

The above snippet works totally fine in all browsers but not in Opera Neon. Download link here.

I tried consoling the typeof domElement.append function it said "undefined". The output is "function" for the same in rest of the browsers.

Any hint on this issue is highly appreciated.


Solution

  • Have recently had this issue - DOMElement.append is NOT what you want DOMElement.appendChild() is what you want.

    As to the question of why does append() work on some browsers (Chrome for windows works but not chrome for OSX???) I really don't know - there doesn't seem to be much documentation for append() anywhere but it does work on many desktop browsers and mobile browsers.