Created
March 2, 2012 00:30
-
-
Save elijahmanor/1954271 to your computer and use it in GitHub Desktop.
Find the jQuery Bug #7: Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <label for="attendee-name">Attendee Name</label> | |
| <input id="attendee-name" type="text"></input> | |
| <button id="register" data-target="#attendee-name">Register</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Conference.prototype.register = function( e ) { | |
| var $attendee = $( $( e.target ).data( "target" ) ); | |
| /* The "this" parameter refers to the register button DOM element | |
| and NOT the object that we were expecting... */ | |
| this.attendees.push( $attendee.val() ); | |
| alert( "Thanks for registering for " + this.name + ". " + | |
| "There are " + this.attendees.length + | |
| " registered thus far." ); | |
| $attendee.val( "" ); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Conference = function( name ) { | |
| this.name = name; | |
| this.attendees = []; | |
| }; | |
| Conference.prototype.register = function( e ) { | |
| var $attendee = $( $( e.target ).data( "target" ) ); | |
| this.attendees.push( $attendee.val() ); | |
| alert( "Thanks for registering for " + this.name + ". " + | |
| "There are " + this.attendees.length + | |
| " registered thus far." ); | |
| $attendee.val( "" ); | |
| }; | |
| var conference = new Conference( "JavaScript Code Camp" ); | |
| $( document ).ready( function() { | |
| $( "#register" ).on( "click", conference.register ); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment