B4J Question handle click event for html element with id that was added in runtime?

ilan

Expert
Licensed User
Longtime User
(i am not sure if i should start a new thread or continue in the old one since it has to do with the old thread: https://www.b4x.com/android/forum/threads/jserver-jqueryelement.130372/ )

hi
so now i know how i can access HTML elements that were created on runtime. my question is how can i trigger a click event on those elements?

right now what i do is 2 solutions.

1. put the button in a form and handle it with ServletRequest.
2. add my own event listener by using inline javascript function and ws.Eval() command.

is there a way i could create a JQueryElement Click event before i have added the element and trigger it there?

like:


B4X:
Sub Class_Globals
    Private mybtn As JQueryElement
End Sub

'..

Private Sub mybtn_Click (Params As Map)
    'do something'
End Sub

but the button will be added in runtime with the id="mybtn". will that work? or is there another solution?
it works fine now by adding the eventlistner by code but it is hard to read and maintain such a project wont be easy. i would preffer to have it in b4x code then in js.

thanx
 
Top