> Recently I've been trying to use ON with jQuery. I met with obstacle.
> I couldn't use "this" keyword in certain cases to get my main object
> reference...
>
> var myObject = {
>
> layout: { 'align': '' },
> start: function() {
> $('form').bind('submit', this.buildLayout); //WORKS
> },
>
> buildLayout: function() {
> this.layout.align = $('#elem').attr('value'); //DOESN'T
WORK
> }
> }
>
> function initialize() {
> myObject.start();
> }
>
> $().ready(initialize);
Nate's solution is a good one, but personally I would probably do this:
$(function() {
var layout = { 'align': '' };
$('form').bind( 'submit', function() {
layout.align = $('#elem').attr( 'value' );
});
});
Of course, it's hard to tell from a stripped-down example whether that
approach would fit with the rest of the code in your application, but it's
always worth looking at a couple of different ways to tackle a problem.
-Mike
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/