button event is not working in fire fox os

放肆的年华 提交于 2019-12-02 04:01:29

Use event delegation

Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.

For dynamically added elements use static parent to add event to the dynamically added elements.

$('#results').on('click', '#upload', function () {
    // Handler here
});

See Doc: on

Your problem:

You are creating an element upload on onsuccess function call. This call can be made after some time-async and your binding onclick is made on spot, when your #upload button may not be yet added to DOM. That is why you need to attach click event to an alement that is already present in DOM, like results:

That is why you need to get existing element (results) and bind: in any #upload will be attached to this one, give him this onclick event.

$('#results').on('click', '#upload', function () {
    // Handler here
});

I hope I had explained your problem.

UPDATE: You could move your click binding under line:

console.log('button uploded!' + r);

This way your click event will be added only when your upload button is attached.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!