TypeError: undefined is not a function

I am using this script:

if (window.matchMedia("(max-width: 1440px)").matches) {
var a = document.createElement("a");
var ulist = document.getElementById("areas");
var newItem = document.createElement("p");
a.textContent = "PRACTICE";
a.setAttribute('href', "practice");
newItem.appendChild(a);
ulist.prepend(newItem);
}

It works fine but in iphone, which displays this error:

TypeError: undefined is not a function (evaluating ‘ulist.prepend(newItem)’)

Is something wrong with the script?

I have a few questions

  • What does your HTML look like?
  • Are there any differences between the HTML where it does work, and what appears on the iPhone?
  • Which browser are you using on the iPhone?
  • Have you tried any other browsers on the iPhone?

The prepend method is not supported in iOS Safari up to version 9.3
You might want to investigate more widely compatible ways to achieve the same thing.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.