Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

First study the enemy. Seek weakness. -- Romulan Commander, "Balance of Terror", stardate 1709.2


devel / alt.html / Re: Select a <td> element with a single onclick() function in <table> ?

SubjectAuthor
* Select a <td> element with a single onclick() function in <table> ?Janis Papanagnou
+* Re: Select a <td> element with a single onclick() function in <table> ?JJ
|`* Re: Select a <td> element with a single onclick() function in <table> ?Janis Papanagnou
| `* Re: Select a <td> element with a single onclick() function in <table> ?Janis Papanagnou
|  `- Re: Select a <td> element with a single onclick() function in <table> ?JJ
`- Re: Select a <td> element with a single onclick() function in <table> ?Jonathan N. Little

1
Select a <td> element with a single onclick() function in <table> ?

<uolgpp$mkvp$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=780&group=alt.html#780

 copy link   Newsgroups: alt.html
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: alt.html
Subject: Select a <td> element with a single onclick() function in <table> ?
Date: Mon, 22 Jan 2024 11:42:00 +0100
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <uolgpp$mkvp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 22 Jan 2024 10:42:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="036ef4b296a1c30a18efabfbd1fdb856";
logging-data="742393"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LX1fnpDyR8cEgsYI00+gw"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:IVW16ry4oQpAaXOc6JZIMDwEpug=
X-Mozilla-News-Host: news://news.eternal-september.org:119
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Mon, 22 Jan 2024 10:42 UTC

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)?

Thanks.

Janis

Re: Select a <td> element with a single onclick() function in <table> ?

<1llb6mjymj2a5.sfurvj70yzqp.dlg@40tude.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=782&group=alt.html#782

 copy link   Newsgroups: alt.html
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: jj4pub...@outlook.com (JJ)
Newsgroups: alt.html
Subject: Re: Select a <td> element with a single onclick() function in <table> ?
Date: Mon, 22 Jan 2024 22:27:11 +0700
Organization: To protect and to server
Message-ID: <1llb6mjymj2a5.sfurvj70yzqp.dlg@40tude.net>
References: <uolgpp$mkvp$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: paganini.bofh.team; logging-data="1376406"; posting-host="r23+qnWvBP/8zF6MtWQekQ.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha256:DcBqn0hhNwtTdfPvkmPI3ruOMIcD8yXHIlPwZCOBMJc=
X-Notice: Filtered by postfilter v. 0.9.3
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
 by: JJ - Mon, 22 Jan 2024 15:27 UTC

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)?
>
> Thanks.
>
> Janis

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) {
//...
}

Re: Select a <td> element with a single onclick() function in <table> ?

<uom4ld$q1ie$2@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=784&group=alt.html#784

 copy link   Newsgroups: alt.html
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: alt.html
Subject: Re: Select a <td> element with a single onclick() function in <table>
?
Date: Mon, 22 Jan 2024 17:21:01 +0100
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <uom4ld$q1ie$2@dont-email.me>
References: <uolgpp$mkvp$1@dont-email.me>
<1llb6mjymj2a5.sfurvj70yzqp.dlg@40tude.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 22 Jan 2024 16:21:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="036ef4b296a1c30a18efabfbd1fdb856";
logging-data="853582"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Zpup6YSGo1Rr4K3WpfGNq"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:ZaF9icqhMrkvS3zwi+IadyV5ykQ=
In-Reply-To: <1llb6mjymj2a5.sfurvj70yzqp.dlg@40tude.net>
 by: Janis Papanagnou - Mon, 22 Jan 2024 16:21 UTC

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!

Janis

Re: Select a <td> element with a single onclick() function in <table> ?

<uomamb$rapi$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=785&group=alt.html#785

 copy link   Newsgroups: alt.html
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: alt.html
Subject: Re: Select a <td> element with a single onclick() function in <table>
?
Date: Mon, 22 Jan 2024 19:03:54 +0100
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <uomamb$rapi$1@dont-email.me>
References: <uolgpp$mkvp$1@dont-email.me>
<1llb6mjymj2a5.sfurvj70yzqp.dlg@40tude.net> <uom4ld$q1ie$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 22 Jan 2024 18:03:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="66734decc3201fad6f2dfa4ae1ebf74f";
logging-data="895794"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sM1nWX/eZ2opQQpsAAAl4"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:MFSAaAt2cOyS7x08dDOBpocWQPo=
In-Reply-To: <uom4ld$q1ie$2@dont-email.me>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Mon, 22 Jan 2024 18:03 UTC

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

Re: Select a <td> element with a single onclick() function in <table> ?

<9gnxtai119p0$.3v8gavmpaxcs$.dlg@40tude.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=786&group=alt.html#786

 copy link   Newsgroups: alt.html
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: jj4pub...@outlook.com (JJ)
Newsgroups: alt.html
Subject: Re: Select a <td> element with a single onclick() function in <table> ?
Date: Tue, 23 Jan 2024 09:33:02 +0700
Organization: To protect and to server
Message-ID: <9gnxtai119p0$.3v8gavmpaxcs$.dlg@40tude.net>
References: <uolgpp$mkvp$1@dont-email.me> <1llb6mjymj2a5.sfurvj70yzqp.dlg@40tude.net> <uom4ld$q1ie$2@dont-email.me> <uomamb$rapi$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: paganini.bofh.team; logging-data="1593691"; posting-host="r23+qnWvBP/8zF6MtWQekQ.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha256:3SmHUtz52AYAzk5lZ1arNd/GNt0baZqPO69x5+aZz5w=
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Notice: Filtered by postfilter v. 0.9.3
 by: JJ - Tue, 23 Jan 2024 02:33 UTC

On Mon, 22 Jan 2024 19:03:54 +0100, Janis Papanagnou wrote:
> 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

If you want `this` in the function to refer to the element, do it like
below.

onclick="f.call(this)"

Odd that the `event` is not available within that function. Unless... a code
was executed asyncronously. i.e. executed later after the event has been
handled.

Re: Select a <td> element with a single onclick() function in <table> ?

<uooefn$19mis$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=787&group=alt.html#787

 copy link   Newsgroups: alt.html
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lws4...@gmail.com (Jonathan N. Little)
Newsgroups: alt.html
Subject: Re: Select a <td> element with a single onclick() function in <table>
?
Date: Tue, 23 Jan 2024 08:20:53 -0500
Organization: LITTLE WORKS STUDIO
Lines: 65
Message-ID: <uooefn$19mis$1@dont-email.me>
References: <uolgpp$mkvp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 23 Jan 2024 13:20:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5b897850207e25c4d56a925112553201";
logging-data="1366620"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LiigGV3ES0hIO2ESAvLIOHfZjOKvL2vY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.18.1
Cancel-Lock: sha1:kNk68Av4O/eU5utGd398fRaLhsM=
X-Face: o[H8T0h*NGH`K`P)s+4PmYlcy|GNl`~+L6Fi.m:%15m[c%{C7V-ump|WiCYPkQ+hFJhq;XW5^1Rg_El'"fE$~AcYW$Pq\yeh9K_-dJqlQ5\y2\;[yw5DYCtOtsf_.TUy}0U\oL^>[3Y#{AP2^o'bG`bwj`]]UNpCxY\(~xK9b+uZKxrb*4-rkD+
X-Dan: Yes Dan this is a Winbox
In-Reply-To: <uolgpp$mkvp$1@dont-email.me>
 by: Jonathan N. Little - Tue, 23 Jan 2024 13:20 UTC

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)?

I wouldn't use one function on the parent, but rather attached one
function to each element and self-reference in the function to ID the
element clicked:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<title>Attach to Each</title>

<style>
td {
padding: .2em;
border: 1px solid black;
width: 2em;
}
</style>
</head>

<body>
<table>
<tr>
<td id="Sam">Sam</td>
<td id="Jim">Jim</td>
<td id="Bob">Bob</td>
<td id="Pat">Pat</td>
</tr>
</table>

<script>
function whoAmI(e) {
alert('I am ' + e.target.id);
}

const tds = Array.from(document.querySelectorAll('td'));
tds.forEach((element) => {
element.addEventListener('click', whoAmI);
});
</script>
</body>
</html>

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor