From 83dc0c3bed76037e3bed66facc87a5a46597a315 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 25 Jan 2021 12:00:05 +0900 Subject: [PATCH 1/2] Explain how to call getElementById MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I think this is the most usual case of calling `getElementById`, and it’s tricky enough that there should be special documentation to explain it. --- src/Web/DOM/NonElementParentNode.purs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Web/DOM/NonElementParentNode.purs b/src/Web/DOM/NonElementParentNode.purs index 4b6a2bd..e032962 100644 --- a/src/Web/DOM/NonElementParentNode.purs +++ b/src/Web/DOM/NonElementParentNode.purs @@ -16,5 +16,20 @@ foreign import data NonElementParentNode :: Type -- | no such element exists. foreign import _getElementById :: String -> NonElementParentNode -> Effect (Nullable Element) +-- | Get a DOM elemement by its id. +-- | +-- | This example shows how to call `getElementById` to get the "root" element +-- | of an HTML5 DOM. +-- | +-- | ```purescript +-- | import Web.HTML (window) -- from purescript-web-html +-- | import Web.HTML.Window (document) -- from purescript-web-html +-- | import Web.HTML.HTMLDocument (toDocument) -- from purescript-web-html +-- | import Web.DOM.Document (toNonElementParentNode) +-- | +-- | do +-- | n <- map toNonElementParentNode $ map toDocument $ document =<< window +-- | e <- getElementById "root" n +-- | ``` getElementById :: String -> NonElementParentNode -> Effect (Maybe Element) getElementById eid = map toMaybe <<< _getElementById eid From 76d04d332adccd99e88183bad7d93c4d3c9d0fd3 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 25 Jan 2021 12:07:53 +0900 Subject: [PATCH 2/2] Doc improvement --- src/Web/DOM/NonElementParentNode.purs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Web/DOM/NonElementParentNode.purs b/src/Web/DOM/NonElementParentNode.purs index e032962..61eab95 100644 --- a/src/Web/DOM/NonElementParentNode.purs +++ b/src/Web/DOM/NonElementParentNode.purs @@ -16,9 +16,10 @@ foreign import data NonElementParentNode :: Type -- | no such element exists. foreign import _getElementById :: String -> NonElementParentNode -> Effect (Nullable Element) --- | Get a DOM elemement by its id. +-- | The first element within a node’s descendants with a matching ID, or `null` if +-- | no such element exists. -- | --- | This example shows how to call `getElementById` to get the "root" element +-- | This example shows how to call `getElementById` to get the `"root"` element -- | of an HTML5 DOM. -- | -- | ```purescript