Created
January 14, 2024 16:25
-
-
Save piq9117/8e711a44cbff5d7e2fa4e6e11e85612b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Effect (Effect) | |
import Effect.Console (log) | |
import Web.HTML as Web | |
import Web.HTML.Window as Window | |
import Web.HTML.HTMLDocument as HTMLDocument | |
import Web.DOM.ParentNode | |
( ParentNode | |
, QuerySelector(..) | |
, querySelector | |
) | |
import Data.Maybe (Maybe(..)) | |
import Web.DOM.Internal.Types (Element) | |
import Web.DOM.Document (createElement) | |
import Web.DOM.Node (setTextContent, appendChild) | |
import Web.DOM.Element as Element | |
main :: Effect Unit | |
main = do | |
window <- Web.window | |
document <- Window.document window | |
let parentNode = HTMLDocument.toParentNode document | |
appElement <- getElement parentNode "#app" | |
h1 <- createElement "h1" (HTMLDocument.toDocument document) | |
setTextContent "Hello, World" (Element.toNode h1) | |
case appElement of | |
Nothing -> log "No app element" | |
Just app -> appendChild (Element.toNode h1) (Element.toNode app) | |
getElement | |
:: ParentNode | |
-> String | |
-> Effect (Maybe Element) | |
getElement pNode selector = | |
querySelector (QuerySelector selector) pNode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment