Skip to content

Instantly share code, notes, and snippets.

@jferris
Created October 10, 2014 18:04
Show Gist options
  • Save jferris/2b77f459226560fc03a2 to your computer and use it in GitHub Desktop.
Save jferris/2b77f459226560fc03a2 to your computer and use it in GitHub Desktop.
DOM Manipulation with ghcjs
module Main (main) where
import Control.Applicative ((<$>))
import GHCJS.DOM (runWebGUI, webViewGetDomDocument)
import GHCJS.DOM.Document (documentGetBody, documentCreateElement)
import GHCJS.DOM.Types (castToHTMLDivElement)
import GHCJS.DOM.Node (nodeAppendChild)
import GHCJS.DOM.HTMLElement (htmlElementSetInnerText)
main :: IO ()
main = do
runWebGUI $ \webView -> do
Just doc <- webViewGetDomDocument webView
Just body <- documentGetBody doc
Just div <- fmap castToHTMLDivElement <$> documentCreateElement doc "div"
htmlElementSetInnerText div "Hello, world!"
nodeAppendChild body $ Just div
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment