Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js View Click event selector syntax?

I'm trying to add an event to my backbone view I have setup. I want to bind the event to an div in the element of view but I want to select that div by two classes.

Example:

<div id="mainContent">
     <div class="small docs"></div>
</div>


        Views.Main = Backbone.View.extend({
            el: $("#mainContent"),

            events: {
                "click .small .docs": "renderActiveDocs"

            },

                        initialize: function () {...}
                });

Having it set up this way doesn't seem to fire that click. If I remove either of the classes and just leave one, then it works.

However the class of this div will change from "small" to "large" and I don't want the click event to fire in that case.

Am I missing something in the syntax or is this not possible?

like image 339
Collin Estes Avatar asked Oct 19 '11 17:10

Collin Estes


People also ask

Which of the following is the correct syntax for creating backbone view?

js view class to create a custom view. Syntax: Backbone. View.

How do you trigger an event in the backbone?

Backbone. js trigger Event is used to invoke or callback the function for the given event or a space-delimited list of events. The subsequent arguments will be passed along to the event callbacks in order to trigger it.

Which of the following is the correct syntax for creating backbone collection with model model?

The Backbone. js collection models specify the array or models which are created inside of a collection. Syntax: collection.


1 Answers

click .small.docs

No space between the two classes.

Reference: second example here: http://api.jquery.com/class-selector/

like image 67
Dheeraj Kumar Avatar answered Oct 04 '22 14:10

Dheeraj Kumar