Question about Javascript, Backbone.js and clicking forms.
I'm working with some hastily-written Backbone.js
code that's supposed to catch clicks from a form, and then respond to those clicks. But the event handling isn't working across different browsers.
The key line of contention is this:
eventType = event.target.type;
Firefox says "event" isn't defined. As a newbie, I'm confused about how to make it see this event, which is bound to actions elsewhere in the code (in the View). Is there some standard way of doing this cross-browser, with jQuery, to make FF and IE alike deal well with this?
Any help much appreciated.
1) You should absolutely be using jquery to be doing anything with js these days. It turns what used to be days of work into 5 minutes.
2) "event" is usually defined as a param of the function that is handling the event. So for example if you have:
$('.thingie').on('click', function() { //do things })
you can put the event as a param, like this:
$('.thingie').on('click', function(event) { //do things })
then use it inside the "do things" method. "Event" is not a magic reserved word, I usually just call it "e" but anything is fine, it will always be the first param of that event handler function.
Hope that helps!
posted by drjimmy11 at 6:10 PM on December 6, 2012