detect id of a clicked button belonging to a class

17 views
Skip to first unread message

chris tophe

unread,
Mar 17, 2018, 2:29:17 PM3/17/18
to brython
Hi,
i have several buttons belonging the same class i called .marked

i want to know, among this class, wich button was just clicked:

<script type="text/python">
from browser import document, ajax, alert

marked_class = document.select('.marked')

@document.select(marked_class).bind("click")
def echo(ev):
    alert(ID OF THE BUTTON I JUSTED CLICKED)

</script>

Glenn Linderman

unread,
Mar 17, 2018, 2:32:57 PM3/17/18
to bry...@googlegroups.com
Read the documentation for Javascript events, and in particular, the atttributes of the event object (which you have named ev) that is passed to the event handler.

Pierre Quentel

unread,
Mar 19, 2018, 3:21:24 AM3/19/18
to brython

For the moment you can't attach the same callback function to all the elements returned by select(), but this is something I have on my todo list
 
Reply all
Reply to author
Forward
0 new messages