Yes, here the problem is your use of this in the Direct function. It will refer to the this defined in the context of the toggle function itself, rather than the callback that calls it.

The DOM element is available in the callback as element.Dom. So you can do something like this:

1
2
3
4
5
6
7
8
9
// $element refers to the function's argument called element.
[<Direct "$element.classList.toggle('hover');">]
let toggle (element: Dom.Element) = X<unit>

let showAnswer () =
  Div [ (* ... *) ]
  |>! OnEvent "touchstart" (fun element event ->
    toggle element.Dom
  )
By on 5/6/2015 10:17 AM ()

I just tried your code, and it works very well. I thank you.

By on 5/6/2015 10:45 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper