admin管理员组

文章数量:1278721

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?

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?

Share Improve this question asked Oct 19, 2011 at 17:50 Collin EstesCollin Estes 5,7997 gold badges53 silver badges71 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

click .small.docs

No space between the two classes.

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

本文标签: javascriptBackbonejs View Click event selector syntaxStack Overflow