javascript – backbone.js – events, knowing what was clicked-ThrowExceptions

Exception or error:

In one of my backbone.js view classes, I have something like:


events: {
  'click ul#perpage span' : 'perpage'

perpage: function() {
  // Access the text of the span that was clicked here
  // Something like: alert($(element).text())


because my per page markup might have something like:

<ul id="perpage">

So how exactly can I find information about the element that caused the event? Or in this instance, that was clicked?

How to solve:

Normally on an event bind, you would just use $(this), but I’m fairly sure Backbone views are set up so that this always refer to the view, so try this:

perpage: function(ev) {

REALLY LATE EDIT: You probably want to use $(ev.currentTarget). See dicussion on pawlik’s answer below

### can be misleading, you should use ev.currentTarget as described on


You can get any attribute you want. ev works as this:

perpage: function(ev) {

Leave a Reply

Your email address will not be published. Required fields are marked *