Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #35982 > unrolled thread
| Started by | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| First post | 2019-02-05 22:59 +0100 |
| Last post | 2019-02-07 13:38 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.javascript
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Attributes containing JavaScript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-02-05 22:59 +0100
Re: Attributes containing JavaScript Julio Di Egidio <julio@diegidio.name> - 2019-02-06 20:10 -0800
Re: Attributes containing JavaScript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-02-07 13:38 +0100
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2019-02-05 22:59 +0100 |
| Subject | Re: Attributes containing JavaScript |
| Message-ID | <XnsA9EDE9DEA82B1eejj99@194.109.6.166> |
ram@zedat.fu-berlin.de (Stefan Ram) wrote on 05 Feb 2019 in
comp.lang.javascript:
> From the point of programming style, how do you assess the
> following two approaches to add a click-handler?
>
> 1.) Add the handler in JavaScript
>
> <span id="span">
> ..
> incrementSpan = () => span.innerHTML = +span.innerHTML + 1;
> span.addEventListener( "click", incrementSpan );
>
> 2.) Add the handler in HTML
>
> <span id="span" onclick="span.innerHTML = +span.innerHTML + 1">0</span>
>
> (end of "2.)")
>
> What are the advantages and disadvantages of each approach?
I would:
not use any id,
generalize the declared function,
so it will be valid in all called elements,
use non-numeric content as 0.
<span onclick='incrementing(this);'>0</span>
<br>
<b onclick='incrementing(this);'>17</b>
<div onclick='incrementing(this);'>zero</div>
<script>
const incrementing = (t) => {
t.innerHTML = (+t.innerHTML || 0) + 1;
};
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-02-06 20:10 -0800 |
| Message-ID | <4caff93b-428d-420b-bbd5-65e2aa0d8dd6@googlegroups.com> |
| In reply to | #35982 |
On Tuesday, 5 February 2019 22:59:29 UTC+1, Evertjan. wrote: > ram@zedat.fu-berlin.de (Stefan Ram) wrote on 05 Feb 2019 in > comp.lang.javascript: > > What are the advantages and disadvantages of each approach? > > I would: > not use any id, What are the advantages and disadvantages of each approach? Ah, sorry, I forget you are just another resident TROLL. *Troll Alert* Julio
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2019-02-07 13:38 +0100 |
| Message-ID | <XnsA9EF8AD225C95eejj99@194.109.6.166> |
| In reply to | #35986 |
Julio Di Egidio <julio@diegidio.name> wrote on 07 Feb 2019 in comp.lang.javascript: > On Tuesday, 5 February 2019 22:59:29 UTC+1, Evertjan. wrote: >> ram@zedat.fu-berlin.de (Stefan Ram) wrote on 05 Feb 2019 in >> comp.lang.javascript: > >> > What are the advantages and disadvantages of each approach? >> >> I would: >> not use any id, > > What are the advantages and disadvantages of each approach? Each, you only specify one. That one, that: the function can be used in one to many places. the function can bereused elswhere where you are yet unaware of. you train yourself to use reuable code. > Ah, sorry, I forget you are just another resident TROLL. > > *Troll Alert* You must feel misearable today, I hope tomorrow is a better day for you. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web