0

I'm trying to rewrite some code from JavaScript with "jQuery" to "Scala js" with "scalajs-jquery"

Here is my code:

val imgWidth: Int = jQuery(".advertise-wrap img").get(0).asInstanceOf[dom.html.Image].naturalWidth

This gives me error in web browser console:

jQuery$1(...).get(...) is undefined

What I'm doing wrong? How correctly to get first element?

sergeda
  • 2,061
  • 3
  • 20
  • 43
  • 1
    It looks like you're doing the right thing. Are you sure `jQuery(".advertise-wrap img")` returns a non-empty selection? What if you `println(jQuery(".advertise-wrap img").length)`? – sjrd Mar 02 '16 at 14:51
  • You are right. Thank you. Just silly mistake. Make your comment answer please – sergeda Mar 02 '16 at 19:13

1 Answers1

0

It looks like you're doing the right thing. Make sure that jQuery(".advertise-wrap img") returns a non-empty selection. For example, you can test that with

println(jQuery(".advertise-wrap img").length)
sjrd
  • 21,805
  • 2
  • 61
  • 91