GoogleChrome / dialog-polyfill

Polyfill for the HTML dialog element
BSD 3-Clause "New" or "Revised" License
2.45k stars 245 forks source link

RegisterModal with CLASS or ID ? #188

Closed sadeghbarati closed 4 years ago

sadeghbarati commented 5 years ago
var dialog = document.querySelector('.class' OR '#id' OR 'ArrayList of Elements'); 
dialogPolyfill.registerDialog(dialog)
dialog.showModal();
if (element.localName !== 'dialog') {
            throw new Error('Failed to register dialog: The element is not a dialog.');
}
sadeghbarati commented 5 years ago

register modal with arrayList not register and throw this error Failed to register dialog: The element is not a dialog.

cp79shark commented 4 years ago

I ran into this check failing because I was using document.createElement("DIALOG") instead of document.createElement("dialog"). At least in Edge, the first call with capital letters results in a HTMLUnknownElement without a localName of dialog. document.querySelector() should be fine using class or id as long as that class/id evaluates first to a <dialog> element that you created in the HTML or via document.createElement("dialog").

I'm not sure what you mean by ArrayList of Elements, that wouldn't be valid for document.querySelector(). See https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors