1

In JQuery I can do something like:

$("#p1").css("color","red").slideUp(2000).slideDown(2000);

:and it runs them in order, but when I try the following in Clojurescript JayQ:

(-> $("#p1")
  (css "color" "red")
  (slideUp 2000)
  (slideDown 2000)
)

: then the methods do not run one after the other. Any ideas on how I can do this?

2 Answers 2

9

I can't speak to jayq, but if you are trying to interop directly with jQuery you need to use the dot syntax to interop:

(-> (js/$ "#p1")
    (.css "color" "red")
    (.slideUp 2000)
    (.slideDown 2000))
Sign up to request clarification or add additional context in comments.

2 Comments

What about the (css {:color "red"}), is it needed?
If you pass a ClojureScript hashmap to jQuery, it will explode with confusion. You can create a plain JavaScript object in ClojureScript pretty easily though: (js-obj) and then use aset and aget to set and get properties (be sure to use strings instead of keywords for the keys).
3

The JayQ syntax is slightly different. This should be more accurate:

(-> ($ "#p1")
    (css {:color "red"})
    (slide-up 2000)
    (slide-down 2000))

2 Comments

Thanks, I missed the extra braces!
I think there is more syntactic differences. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.