jQuery .on trigger no activa la acción

Tengo esta forma:

$form = array(
        '<form name="backup-form" class="backup-form" method="post" action="#">',
            '<fieldset class="backup-fields">',
                '<fieldset class="display-wrapper">',
                    '<label for="display" class="display-label">Backups</label>',
                    '<input type="text" name="display" class="display" value="' . $this->backups(false,true) . '" autocomplete="off" readonly="readonly" />',
                '</fieldset>',
                '<fieldset class="action-wrapper">',
                    '<button type="submit" name="clean" class="clean">Clean All</button>',
                    '<button type="submit" name="create" class="create">Create</button>',
                '</fieldset>',
            '</fieldset>',
        '</form>',
        '<div class="message-handling" class="message-handling"></div>'
    );
$form = implode("", $form);
echo $form;

And I'm trying to bind an even to each submit button like this:

$('.backup-form .clean').on({
    click: function() {console.log('Clean Button Pressed');}
});

or

$('.main-actions .backup-form').delegate('.clean', 'submit', function() {
    console.log('Clean Button Pressed');    
});

But none of it works. What's happening ? Or what should I do to make it work ?

preguntado el 02 de febrero de 12 a las 11:02

I cannot use it, because this script is on a page loaded with ajax by jQuery Tools's tabs, so no $(document).ready(function(){ ... }) esta permitido. -

1 Respuestas

try, if you are dynamically adding the form

$(function(){
    $(document).delegate('.clean', 'submit', function() {
        console.log('Clean Button Pressed');    
    });
}

or if not this should work

$(function(){
$('.main-actions .backup-form').delegate('.clean', 'submit', function() {
    console.log('Clean Button Pressed');    
});
}

Respondido 02 Feb 12, 15:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.