espvar
espvar

Reputation: 1065

Javascript paste event iPhone

I wan't to capture a paste event on iPhone. Using Javascript jQuery. I'we tried jQuery keyup and paste without luck. Any suggestions?

This is what I've got:

 $("#MyInputFields input").eq(0).bind("keyup paste", function () {
    //do something
});

Everything works fine if the user types the value in the input field, but if the user pastes the text it does not fire.

Upvotes: 0

Views: 2866

Answers (1)

gdoron
gdoron

Reputation: 150303

If your selector is correct, I think the only option is that you are missing the DOM ready, because everything else in that code looks o.k.

 $(function (){ $("#MyInputFields input").eq(0).bind("keyup paste", function () {
        //do something
    });
});

Unless those inputs aren't present in the page when this line executed, then you need to use delegate event like on\ delegate \ live :

$('body').on("keyup paste", "#MyInputFields input", function () {
        //do something
    });

chose the function base on your jquery version:

$(selector).live(events, data, handler);                // jQuery 1.3+
$(document).delegate(selector, events, data, handler);  // jQuery 1.4.3+
$(document).on(events, selector, data, handler);        // jQuery 1.7+

Upvotes: 1

Related Questions