Skip to content

Commit 57fac5c

Browse files
gzm0sjrd
authored andcommitted
Step 3: Using the DOM
1 parent 488f06a commit 57fac5c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ scalaVersion := "2.13.1"
55

66
// This is an application with a main method
77
scalaJSUseMainModuleInitializer := true
8+
9+
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "1.0.0"
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package tutorial.webapp
22

3+
import org.scalajs.dom
4+
import org.scalajs.dom.document
5+
36
object TutorialApp {
47
def main(args: Array[String]): Unit = {
5-
println("Hello world!")
8+
appendPar(document.body, "Hello World")
9+
}
10+
11+
def appendPar(targetNode: dom.Node, text: String): Unit = {
12+
val parNode = document.createElement("p")
13+
val textNode = document.createTextNode(text)
14+
parNode.appendChild(textNode)
15+
targetNode.appendChild(parNode)
616
}
717
}

0 commit comments

Comments
 (0)