Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32259 > unrolled thread
| Started by | bit-naughty@hotmail.com |
|---|---|
| First post | 2017-01-22 22:55 -0800 |
| Last post | 2017-01-25 17:42 +0100 |
| Articles | 20 on this page of 32 — 7 participants |
Back to article view | Back to comp.lang.javascript
Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-22 22:55 -0800
Re: Having to click TWICE for event Maik Koenig <usenetspam@maikkoenig.de> - 2017-01-23 09:08 +0100
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-23 10:47 -0800
Re: Having to click TWICE for event Maik Koenig <usenetspam@maikkoenig.de> - 2017-01-23 22:45 +0100
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-24 06:00 -0800
Re: Having to click TWICE for event Ram Tobolski <ramtob@gmail.com> - 2017-01-24 10:27 -0800
Re: Having to click TWICE for event jonas.thornvall@gmail.com - 2017-01-24 10:55 -0800
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-24 11:05 -0800
Re: Having to click TWICE for event Ram Tobolski <ramtob@gmail.com> - 2017-01-24 13:10 -0800
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-24 22:56 -0800
Re: Having to click TWICE for event Maik Koenig <usenetspam@maikkoenig.de> - 2017-01-25 11:55 +0100
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-25 07:03 -0800
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-26 23:59 -0800
Re: Having to click TWICE for event Ram Tobolski <ramtob@gmail.com> - 2017-01-25 11:05 -0800
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-24 23:25 -0800
Re: Having to click TWICE for event Maik Koenig <usenetspam@maikkoenig.de> - 2017-01-25 11:57 +0100
Re: Having to click TWICE for event Ram Tobolski <ramtob@gmail.com> - 2017-01-25 11:14 -0800
Re: Having to click TWICE for event Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2017-01-24 21:41 +0100
Re: Having to click TWICE for event Ram Tobolski <ramtob@gmail.com> - 2017-01-24 13:13 -0800
Re: Having to click TWICE for event "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-24 23:46 +0100
Re: Having to click TWICE for event Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2017-01-25 00:20 +0100
Re: Having to click TWICE for event "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-25 11:19 +0100
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-24 23:00 -0800
Re: Having to click TWICE for event Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2017-01-25 09:32 +0100
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-25 07:05 -0800
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-26 23:58 -0800
Re: Having to click TWICE for event Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2017-01-27 12:48 +0100
Re: Having to click TWICE for event Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-27 13:13 +0100
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-24 23:03 -0800
Re: Having to click TWICE for event "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-25 11:21 +0100
Re: Having to click TWICE for event bit-naughty@hotmail.com - 2017-01-25 07:10 -0800
Re: Having to click TWICE for event "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-25 17:42 +0100
Page 1 of 2 [1] 2 Next page →
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-01-22 22:55 -0800 |
| Subject | Having to click TWICE for event |
| Message-ID | <508acb43-edf6-446c-9f3e-ec2ebd7979cb@googlegroups.com> |
..I have a link on my webpage, upon clicking of which, I want some stuff to happen (without a refresh, ie. on THAT page). This is my code:
<div id="myid" align="center">
<a href='javascript:document.getElementById("myid").addEventListener("click", function(event) {
event.preventDefault();
alert("clicked");
}
Now when I click, nothing happens! Then if I click AGAIN, the "clicked" box pops up! - I want it to popup on the FIRST click, obviously. What's going wrong?
Thanks.
[toc] | [next] | [standalone]
| From | Maik Koenig <usenetspam@maikkoenig.de> |
|---|---|
| Date | 2017-01-23 09:08 +0100 |
| Message-ID | <o64h6a.9co.1@mid.maikkoenig.de> |
| In reply to | #32259 |
Am 23.01.2017 um 07:55 schrieb bit-naughty@hotmail.com:
> ...I have a link on my webpage, upon clicking of which, I want some
> stuff to happen (without a refresh, ie. on THAT page). This is my
> code:
>
> <div id="myid" align="center"> <a
> href='javascript:document.getElementById("myid").addEventListener("click",
> function(event) { event.preventDefault(); alert("clicked"); }
>
>
> Now when I click, nothing happens! Then if I click AGAIN, the
> "clicked" box pops up! - I want it to popup on the FIRST click,
> obviously. What's going wrong?
First click: Add eventlistener. Second click: ...
Solution:
<body onload="....
Greetz,
MK
--
Kopp-Verlag-Gläubige, Religionsdeppen, rechte Vollidioten
und ähnlicher Bio-Abfall werden ohne Hinweis ignoriert!
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-01-23 10:47 -0800 |
| Message-ID | <e61763a8-65f3-4241-a37f-f9b789d25342@googlegroups.com> |
| In reply to | #32260 |
On Monday, January 23, 2017 at 2:08:40 AM UTC-6, Maik Koenig wrote: > > First click: Add eventlistener. Second click: ... > > Solution: > > <body onload=".... > Ahh got you. Sorry - body onload=WHAT? (I'm new to this.) addEventListener?
[toc] | [prev] | [next] | [standalone]
| From | Maik Koenig <usenetspam@maikkoenig.de> |
|---|---|
| Date | 2017-01-23 22:45 +0100 |
| Message-ID | <o6612n.998.1@mid.maikkoenig.de> |
| In reply to | #32273 |
Am 23.01.2017 um 19:47 schrieb bit-naughty@hotmail.com: > On Monday, January 23, 2017 at 2:08:40 AM UTC-6, Maik Koenig wrote: > >> >> First click: Add eventlistener. Second click: ... >> >> Solution: >> >> <body onload=".... >> > > > Ahh got you. Sorry - body onload=WHAT? (I'm new to this.) addEventListener? > Yes. Greetz, MK -- Kopp-Verlag-Gläubige, Religionsdeppen, rechte Vollidioten und ähnlicher Bio-Abfall werden ohne Hinweis ignoriert!
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-01-24 06:00 -0800 |
| Message-ID | <14f9d324-b305-499b-a9f4-dcc4729413ce@googlegroups.com> |
| In reply to | #32281 |
On Monday, January 23, 2017 at 3:53:30 PM UTC-6, Maik Koenig wrote: > > Yes. > And then how do you code the link?
[toc] | [prev] | [next] | [standalone]
| From | Ram Tobolski <ramtob@gmail.com> |
|---|---|
| Date | 2017-01-24 10:27 -0800 |
| Message-ID | <77c28034-be7c-4ac6-a967-6d93c83d18a5@googlegroups.com> |
| In reply to | #32296 |
>And then how do you code the link? Hi. You don't need the link (<a>), just the <div>. You are registering a listener to clicks on the <div>
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-01-24 10:55 -0800 |
| Message-ID | <d46d540f-9815-4ade-9e0a-9c0645e217f1@googlegroups.com> |
| In reply to | #32304 |
Den tisdag 24 januari 2017 kl. 19:27:56 UTC+1 skrev Ram Tobolski: > >And then how do you code the link? > > Hi. You don't need the link (<a>), just the <div>. You are registering a listener to clicks on the <div> Well i also have to click twice but that is not the problem because part of the code is executed.
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-01-24 11:05 -0800 |
| Message-ID | <c3fa29cd-21c1-4dc3-9abc-9592d1c23083@googlegroups.com> |
| In reply to | #32304 |
On Tuesday, January 24, 2017 at 12:27:56 PM UTC-6, Ram Tobolski wrote: > >And then how do you code the link? > > Hi. You don't need the link (<a>), just the <div>. You are registering a listener to clicks on the <div> Ahh yes, you're right! :) Can you help me out with coding the <body onload part? I'm not sure of the syntax.... Btw, what's a good forum to ask CSS questions?
[toc] | [prev] | [next] | [standalone]
| From | Ram Tobolski <ramtob@gmail.com> |
|---|---|
| Date | 2017-01-24 13:10 -0800 |
| Message-ID | <cd8fbf19-3908-4790-87e4-11536dd57f1a@googlegroups.com> |
| In reply to | #32306 |
>Can you help me out with coding the <body onload part? I'm not sure of the syntax.... Sure. You can just locate a <script> at the end of the <body>. See: https://jsbin.com/ruradev/edit?html >Btw, what's a good forum to ask CSS questions? Here is one: https://groups.google.com/forum/#!forum/comp.infosystems.www.authoring.stylesheets
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-01-24 22:56 -0800 |
| Message-ID | <13cead90-de25-4215-9e66-f166f8a76e16@googlegroups.com> |
| In reply to | #32311 |
On Tuesday, January 24, 2017 at 3:10:28 PM UTC-6, Ram Tobolski wrote: > >Can you help me out with coding the <body onload part? I'm not sure of the syntax.... > > Sure. You can just locate a <script> at the end of the <body>. See: > > https://jsbin.com/ruradev/edit?html Ah thanks for that, Ram. But that doesn't have a "onload" anywhere....? What was Maik Koenig meaning??
[toc] | [prev] | [next] | [standalone]
| From | Maik Koenig <usenetspam@maikkoenig.de> |
|---|---|
| Date | 2017-01-25 11:55 +0100 |
| Message-ID | <o6a3o9.8cg.1@mid.maikkoenig.de> |
| In reply to | #32324 |
Am 25.01.2017 um 07:56 schrieb bit-naughty@hotmail.com:
> On Tuesday, January 24, 2017 at 3:10:28 PM UTC-6, Ram Tobolski wrote:
>> >Can you help me out with coding the <body onload part? I'm not sure of the syntax....
>>
>> Sure. You can just locate a <script> at the end of the <body>. See:
>>
>> https://jsbin.com/ruradev/edit?html
>
>
> Ah thanks for that, Ram. But that doesn't have a "onload" anywhere....? What was Maik Koenig meaning??
>
> amai liu
<body onload="f();">
<script>
function a() {
document.getElementById('myid').addEventListener('click,
function(event) {
event.preventDefault();
alert('clicked');
};
</script>
http://www.w3schools.com/jsref/event_onload.asp
Greetz,
MK
--
Kopp-Verlag-Gläubige, Religionsdeppen, rechte Vollidioten
und ähnlicher Bio-Abfall werden ohne Hinweis ignoriert!
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-01-25 07:03 -0800 |
| Message-ID | <a9d08e32-ebf4-4620-8b24-9220d0d0c7c9@googlegroups.com> |
| In reply to | #32336 |
On Wednesday, January 25, 2017 at 5:00:13 AM UTC-6, Maik Koenig wrote:
>
> <body onload="f();">
>
> <script>
> function a() {
> document.getElementById('myid').addEventListener('click,
> function(event) {
> event.preventDefault();
> alert('clicked');
> };
> </script>
Ummm.... surely you mean function f() ...?
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-01-26 23:59 -0800 |
| Message-ID | <9ad8ed33-d136-43a9-9942-95ee315ca04b@googlegroups.com> |
| In reply to | #32339 |
> Ummm.... surely you mean function f() ...? Well? - It *is* f() ,right?
[toc] | [prev] | [next] | [standalone]
| From | Ram Tobolski <ramtob@gmail.com> |
|---|---|
| Date | 2017-01-25 11:05 -0800 |
| Message-ID | <d0d99bba-e730-4c5e-a876-eef099b86fde@googlegroups.com> |
| In reply to | #32324 |
> https://jsbin.com/ruradev/edit?html >Ah thanks for that, Ram. But that doesn't have a "onload" anywhere....? What was Maik Koenig meaning?? Maik already answered. I'll just add that as usual there is more than one way to get the objective. Using "onload" is a bit older way, less used today.
[toc] | [prev] | [next] | [standalone]
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-01-24 23:25 -0800 |
| Message-ID | <a7595f9e-3505-4066-a382-347cb06305ec@googlegroups.com> |
| In reply to | #32311 |
On Tuesday, January 24, 2017 at 3:10:28 PM UTC-6, Ram Tobolski wrote: > >Can you help me out with coding the <body onload part? I'm not sure of the syntax.... > > Sure. You can just locate a <script> at the end of the <body>. See: > > https://jsbin.com/ruradev/edit?html > Hey I just tried it - it works fine, but the cursor doesn't change to a hand when it's over the text in the div, i.e. the user won't know it's clickable. How do I do that?
[toc] | [prev] | [next] | [standalone]
| From | Maik Koenig <usenetspam@maikkoenig.de> |
|---|---|
| Date | 2017-01-25 11:57 +0100 |
| Message-ID | <o6a3s6.8cg.1@mid.maikkoenig.de> |
| In reply to | #32327 |
Am 25.01.2017 um 08:25 schrieb bit-naughty@hotmail.com: > On Tuesday, January 24, 2017 at 3:10:28 PM UTC-6, Ram Tobolski > wrote: >>> Can you help me out with coding the <body onload part? I'm not >>> sure of the syntax.... >> >> Sure. You can just locate a <script> at the end of the <body>. >> See: >> >> https://jsbin.com/ruradev/edit?html >> > > > Hey I just tried it - it works fine, but the cursor doesn't change to > a hand when it's over the text in the div, i.e. the user won't know > it's clickable. How do I do that? > http://www.w3schools.com/cssref/pr_class_cursor.asp Greetz, MK -- Kopp-Verlag-Gläubige, Religionsdeppen, rechte Vollidioten und ähnlicher Bio-Abfall werden ohne Hinweis ignoriert!
[toc] | [prev] | [next] | [standalone]
| From | Ram Tobolski <ramtob@gmail.com> |
|---|---|
| Date | 2017-01-25 11:14 -0800 |
| Message-ID | <9d0cd379-b37d-4590-9121-28b06a7da75e@googlegroups.com> |
| In reply to | #32327 |
>
> https://jsbin.com/ruradev/edit?html
>
>Hey I just tried it - it works fine, but the cursor doesn't change to a hand when it's over the text in the div, i.e. the user won't know it's clickable. How do I do that?
You add a style definition. I updated the linked example.
#myId {cursor: pointer}
[toc] | [prev] | [next] | [standalone]
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2017-01-24 21:41 +0100 |
| Message-ID | <o68e5f$onm$1@csiph.com> |
| In reply to | #32304 |
On 24/01/2017 19:27, Ram Tobolski wrote: >> And then how do you code the link? > > Hi. You don't need the link (<a>), just the <div>. You are registering a listener to clicks on the <div> That's not a good idea as the <div> itself is not focusable and the user will not be able to reach this button using keyboard. Except when you add attribute tabindex="0", but I'd rather not use <div> with click event instead use natively focusable <a> HTML element. -- Cezary Tomczyk http://www.ctomczyk.pl/ https://www.aslint.org/ - Accessibility linting tool
[toc] | [prev] | [next] | [standalone]
| From | Ram Tobolski <ramtob@gmail.com> |
|---|---|
| Date | 2017-01-24 13:13 -0800 |
| Message-ID | <7d45ffba-df2f-4c6f-ac82-57d0eaaedf71@googlegroups.com> |
| In reply to | #32310 |
>That's not a good idea as the <div> itself is not focusable and the user will not be able to reach this button using keyboard. Except when you add attribute tabindex="0", but I'd rather not use <div> with click event instead use natively focusable <a> HTML element. Good point
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2017-01-24 23:46 +0100 |
| Message-ID | <XnsA707F1D953F70eejj99@194.109.6.166> |
| In reply to | #32310 |
Cezary Tomczyk <cezary.tomczyk@gmail.com> wrote on 24 Jan 2017 in comp.lang.javascript: > On 24/01/2017 19:27, Ram Tobolski wrote: >>> And then how do you code the link? >> >> Hi. You don't need the link (<a>), just the <div>. You are registering >> a listener to clicks on the <div> > > That's not a good idea as the <div> itself is not focusable and the user > will not be able to reach this button using keyboard. Except when you > add attribute tabindex="0", but I'd rather not use <div> with click > event instead use natively focusable <a> HTML element. Methinks, Cezary, it is a quite marvelous idea for programmers who are painfully aware of their own limitations in sofar as to add a "return false;" at the end of their listener codes, their focus on focusability rather being of another kind. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web