Search code examples
jquerycoffeescriptkoala

how can I use coffeescript with jquery?


I am using the 'Koala' program for CoffeeScript. I will write a coffescript with jQuery. I am writing the following code. Not working

    

$ ->

Output code

    

(Function () {
        $ (function () {});
    }). Call (this);
    

This does not work in SW. Do I make a mistake? Or how can I use coffeescript with jquery?


Solution

  • Here's an example…

    HTML

    <!DOCTYPE html>
      <body>
        <a class='button' href='#'>Click Me</a>
      </body>
    </html>
    

    CoffeeScript

    $ ->
      $('.button').click (event) ->
        console.log 'button clicked'
    

    Click here for live example