How do I use ion-alert in plain javascript

I’m having trouble getting an ion-alert to display for a plain javascript (ionic via CDN) site. The ionic documentation for ion-alert and Javascript shows the following:

function presentAlert() {
  const alert = document.createElement('ion-alert');
  alert.header = 'Alert';
  alert.subHeader = 'Subtitle';
  alert.message = 'This is an alert message.';
  alert.buttons = ['OK'];

  document.body.appendChild(alert);
  return alert.present();
}

However, this only ever results in: “TypeError: alert.present is not a function”

What am I missing?

For anyone who runs into the same issue, I was using this as a splash screen, and I needed to wait and call present after the page loaded, i.e.:

window.addEventListener('load', (event) => { presentAlert(); });
1 Like