Pregunta

I'm having issues getting a jquery .change() event to fire in an Iphone. Code is similar to the following:

var checkboxes = $('#someelement').find('input[type=checkbox]');

checkboxes.change(function() {

//never gets here on iPhone
alert('hello');
});

checkboxes.filter(':checked').trigger('change'); 

The list of checkboxes is generated dynamically before this step, written to the page with an .append() method.

This all works fine in desktop browsers and Android phones. Using JQuery version 1.6.4

Any thoughts?

¿Fue útil?

Solución

Try using delegate, which lets you attach events to current and future elements.

$("#someelement").delegate('input[type="checkbox"]', "change", function(){
  alert('hello');
});

Also, as of jQuery 1.5, all attribute selectors need to be quoted (ex. the "checkbox" in the second selector).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top