Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Janis Papanagnou <janis_papanagnou+ng@hotmail.com> |
|---|---|
| Newsgroups | alt.html |
| Subject | Re: Select a <td> element with a single onclick() function in <table> ? |
| Date | 2024-01-22 19:03 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <uomamb$rapi$1@dont-email.me> (permalink) |
| References | <uolgpp$mkvp$1@dont-email.me> <1llb6mjymj2a5.sfurvj70yzqp.dlg@40tude.net> <uom4ld$q1ie$2@dont-email.me> |
On 22.01.2024 17:21, Janis Papanagnou wrote:
> On 22.01.2024 16:27, JJ wrote:
>> On Mon, 22 Jan 2024 11:42:00 +0100, Janis Papanagnou wrote:
>>> With a single onclick() definition on the <table> level
>>>
>>> <table onclick="f()">
>>> <tr>
>>> <td id="11">
>>> ....
>>> <td id="42">
>>> ....
>>>
>>> is it possible to get in f() the concrete element that has been
>>> clicked on, e.g. the one with id="42" (or do I have to provide
>>> an own onclick() attribute with every single <td> element)?
>>
>> Within that `f()` function, `event` refers to the current (click) event
>> object. Its `target` property refers to the clicked element.
>>
>> Alternatively, pass the `this` keyword as an argument of the `f()` function
>> call. e.g.
>>
>> onclick="f(this)"
>>
>> The `f()` function should be declared as e.g.:
>>
>> function f(clickedEle) {
>> //...
>> }
>>
>
> This is fine. I'll try that in my code. - Thanks!
I couldn't get it working with my HTML event-handler definition
<table ... onclick="f()">
Inside f() the 'event' was undefined, and all I tried with 'this',
'target', 'document', function parameters, access through elements,
and whatnot, did not work. :-(
(And all I found on that topic on the net uses JS event handlers,
addEventListener, not the HTML onclick().)
Installing a JS event handler like this (for example) works:
function f(ev) { alert(ev.target.closest('img').title); }
document.addEventListener('click', f);
I wanted to stay with the onclick="f()" logic, but okay... :-/
Janis
Back to alt.html | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Select a <td> element with a single onclick() function in <table> ? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-01-22 11:42 +0100
Re: Select a <td> element with a single onclick() function in <table> ? JJ <jj4public@outlook.com> - 2024-01-22 22:27 +0700
Re: Select a <td> element with a single onclick() function in <table> ? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-01-22 17:21 +0100
Re: Select a <td> element with a single onclick() function in <table> ? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-01-22 19:03 +0100
Re: Select a <td> element with a single onclick() function in <table> ? JJ <jj4public@outlook.com> - 2024-01-23 09:33 +0700
Re: Select a <td> element with a single onclick() function in <table> ? "Jonathan N. Little" <lws4art@gmail.com> - 2024-01-23 08:20 -0500
csiph-web