============
Use ScalablyTyped instead 🙇
Static types for the jQuery API for Scala.js programs.
This library is a fork of sjrd/scala-js-jquery to maintain for newer Scala.js and jQuery.
Currently, jQuery 3.5.1 and above is supported.
Add the following to your sbt build definition:
libraryDependencies += "net.exoego" %%% "scalajs-jquery3" % "2.2.0"
Enjoy types in Scala file:
import net.exoego.scalajs.jquery._
jQuery("button".on("click", () => println("hello world"))
This aritifcat is built and published for
- Scala.js 1.0.0 and later
- with Scala 2.11, 2.12, 2.13, 3.x
- for jQuery 3.4.1 based on this TypeScript definition and manually tweaked
It will likely be published as is for later versions of Scala and Scala.js as well.
This artifact provides type aliases as bridge from the original package
org.scalajs.jquery
to the updated net.exoego.scalajs.jquery
package.
It will allow you to update type facade to jQuery 3 with minimum code change. But you should expect some minor rewrites, since
- Original
org.scalajs.jquery
offers non strict types for jQuery 1/2. net.exoego.scalajs.jquery
offers stricter types for jQuery 3.
Add the following to your sbt build definition:
libraryDependencies += "net.exoego" %%% "scalajs-jquery3-compat" % "2.2.0"
You may use type aliases in org.scalajs.jquery
:
import org.scalajs.jquery._
jQuery("button".on("click", () => println("hello world"))
*** jQuery 1/2 support was removed. Consider upgrading to jQuery 3/4 or remove jQuery. ***
This is a drop-in replacement for original "be.doeraene" %%% "scalajs-jquery" % "0.9.5"
artifact.
Caution: Sources of scalajs-jquery2
are just copy of sjrd/scala-js-jquery and published for newer Scala.js & Scala. The actual supported jQuery version is unknown. It is unlikely to update type facade for this artifact by me (contribution are welcome).
Add the following to your sbt build definition:
libraryDependencies += "net.exoego" %%% "scalajs-jquery2" % "2.0.0" // Final version. Consider upgrading to jQuery 3/4 or remove jQuery.
Enjoy types in Scala file:
import org.scalajs.jquery._
jQuery("button".on("click", () => println("hello world"))
then enjoy the types available in org.scalajs.jquery
.
This aritifcat is built and published for Scala.js 0.6.29 and later, and Scala.js 1.0.0, with Scala 2.11, 2.12, 2.13. It will likely be published as is for later versions of Scala and Scala.js as well.
Using Scala.js Bundler
If you want to use Scala.js Bundler (sbt plugin must be enabled in project/plugins.sbt
) to import jQuery as npm module, then add the following lines to your sbt build definition:
enablePlugins(ScalaJSBundlerPlugin)
libraryDependencies += "net.exoego" %%% "scalajs-jquery3" % "2.2.0"
npmDependencies in Compile ++= Seq(
 "jquery" -> "3.5.0"
)
Then define a jquery
object in your Scala code using the @JSImport
annotation to get access to the exported jQuery
object.
A simple example on how to use the Scala.js JQuery facade this way is shown here:
import net.exoego.scalajs.jquery.{ JQueryStatic => jquery }
object Main {
override def main(): Unit = {
jquery("body").html("Hello world!")
}
}
Running the sbt task fastOptJS::webpack
will generate a JavaScript bundle (...-fastopt-bundle.js
) including jquery as specified in the npmDependencies
sbt build definition setting.