Q:

CanJS click event doesn't work

I am using CanJS (a js framework) for my project. but I have a problem.
I've written some code in book.js as follows:
Book = can.Model({
    create: 'POST site/book'
},{});

Books = can.Control({

        '.gotoPrevPage click' : function(){
            b= new Book({name:"newbook1"});
            b.save();
        }
});

and also, my html file is as follows:
...
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/can.jquery-1.0.7.min.js"></script>
<script type="text/javascript" src="js/book.js"></script>
...
<div class="twopageDoc">

    <div class="gotoPrevPage"></div>

    <div class="leftPage">

        <img src="images/1.jpg" />

    </div>

    <div class="rightPage">

        <img src="images/2.jpg" />

    </div>

    <div class="gotoNextPage"></div>

</div>
...

now, when i click on div with class "gotoPrevPage" event doesn't work and i don't see any errors. but when i use Chrome console and write down the 2 line code of the above event the POST is done and it works. I don't know the reason.

A:

From your code it looks like you didn't initialize the controller. You should create instance of the Books on the DOM element:
new Books('.twpopageDoc')

