Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Trigger hover pseudo class using javascript?

Reply
Thread Tools

Trigger hover pseudo class using javascript?

 
 
Ciaran
Guest
Posts: n/a
 
      05-04-2010
On 30 Apr, 15:19, Ry Nohryb <(E-Mail Removed)> wrote:
> On Apr 30, 3:33*pm, Scott Sauyet <(E-Mail Removed)> wrote:
>
>
>
>
>
> > Thomas 'PointedEars' Lahn wrote:
> > > Scott Sauyet wrote:
> > >> I'm curious as to this. *The original question was

>
> > >> | Is it possible to trigger the hover state of an element using
> > >> | javascript?
> > >> [ ... ]
> > >> Are you suggesting that there are circumstances where this can
> > >> be done? *If so, could you elaborate?

>
> > > In W3C DOM Level 2+ Events-compliant implementations you can create and
> > > dispatch events programmatically. *If you create a `mouseover' event and
> > > dispatch it to an element object, it should trigger whatever "hover state"
> > > is supposed to mean of the corresponding element.

>
> > > Cf. <https://developer.mozilla.org/en/DOM/document.createEvent>

>
> > Thank you. *I had never really looked at that before. *It's a shame
> > that this is not implemented universally.

>
> I think it's been implemented in most browsers for a few years now.
> But there's something very important to watch out with events emitted
> in this way: they are handled *synchronously*, they are not queued as
> events usually are, they are instead handled from within the call to
> dispatchEvent():
>
> (function () {
> * var evt = document.createEvent("MouseEvents");
> * evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
> false, false, false, false, 0, null);
> * var ctr= 0;
> * document.body.onclick= function () { ctr++; };
> * document.body.dispatchEvent(evt);
> * console.log(ctr);
> * setTimeout(function(){ console.log(ctr); });
>
> })();
>
> --> 1, 1
> --
> Jorge.




Thanks Jorge. I can't understand why 'PointedEars' did not mention any
of this interesting detail in his initial reply on this thread, or in
even afterwards when I probed further ...But my question has at last
been answered!
Cheers,
Ciaran (OP)
 
Reply With Quote
 
 
 
 
Ry Nohryb
Guest
Posts: n/a
 
      05-04-2010
On May 4, 4:01*am, Ciaran <(E-Mail Removed)> wrote:
> On 30 Apr, 15:19, Ry Nohryb <(E-Mail Removed)> wrote:
> (...)
> > I think it's been implemented in most browsers for a few years now.
> > But there's something very important to watch out with events emitted
> > in this way: they are handled *synchronously*, they are not queued as
> > events usually are, they are instead handled from within the call to
> > dispatchEvent():

>
> > (function () {
> > * var evt = document.createEvent("MouseEvents");
> > * evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
> > false, false, false, false, 0, null);
> > * var ctr= 0;
> > * document.body.onclick= function () { ctr++; };
> > * document.body.dispatchEvent(evt);
> > * console.log(ctr);
> > * setTimeout(function(){ console.log(ctr); });

>
> > })();

>
> > --> 1, 1

>
> Thanks Jorge. I can't understand why 'PointedEars' did not mention any
> of this interesting detail in his initial reply on this thread, or in
> even afterwards when I probed further ...But my question has at last
> been answered!
> Cheers,
> Ciaran (OP)


You're welcome.
--
Jorge.
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      06-27-2010
Ciaran wrote:

> Ry Nohryb wrote:
>> Scott Sauyet wrote:
>> > Thomas 'PointedEars' Lahn wrote:
>> > > Scott Sauyet wrote:
>> > >> I'm curious as to this. The original question was
>> > >>
>> > >> | Is it possible to trigger the hover state of an element using
>> > >> | javascript?
>> > >> [ ... ]
>> > >> Are you suggesting that there are circumstances where this can
>> > >> be done? If so, could you elaborate?
>> > >
>> > > In W3C DOM Level 2+ Events-compliant implementations you can create
>> > > and dispatch events programmatically. If you create a `mouseover'
>> > > event and dispatch it to an element object, it should trigger
>> > > whatever "hover state" is supposed to mean of the corresponding
>> > > element.
>> > >
>> > > Cf. <https://developer.mozilla.org/en/DOM/document.createEvent>
>> >
>> > Thank you. I had never really looked at that before. It's a shame
>> > that this is not implemented universally.

>>
>> I think it's been implemented in most browsers for a few years now.
>> But there's something very important to watch out with events emitted
>> in this way: they are handled *synchronously*, they are not queued as
>> events usually are,


Rubbish. Events are _not_ queued; they are created and dispatched.

>> they are instead handled from within the call to dispatchEvent():


Because the event is dispatched *manually* (here: immediately after
creation).

>> (function () {
>> var evt = document.createEvent("MouseEvents");
>> evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
>> false, false, false, false, 0, null);
>> var ctr= 0;
>> document.body.onclick= function () { ctr++; };
>> document.body.dispatchEvent(evt);
>> console.log(ctr);
>> setTimeout(function(){ console.log(ctr); });


You forgot `window.' and the mandatory second argument in the last
statement, but your example would not prove your argument even if you
didn't.

>> })();
>>
>> --> 1, 1

>
> Thanks Jorge.


For what? Posting nonsense again, while *I* have provided the correct
reference?

> I can't understand why 'PointedEars' did not mention any
> of this interesting detail in his initial reply on this thread,
> or in even afterwards when I probed further


I did on both accounts. And this is not a support forum, so nothing for
you to probe, but a lot for you to learn. Learn to read and to ask smart
questions to begin with.

<http://www.catb.org/~esr/faqs/smart-questions.html>


Score adjusted

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
Ry Nohryb
Guest
Posts: n/a
 
      06-27-2010
On Jun 27, 11:16*am, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> > Ry Nohryb wrote:
> >> But there's something very important to watch out with events emitted
> >> in this way: they are handled *synchronously*, they are not queued as
> >> events usually are,

>
> Rubbish. *Events are _not_ queued;


Yes Pointy, most if not all of the user interface events (click,
scroll, mousemove, etc) are queued, DOM mutation events aren't queued:
they're handled synchronously, as is the first onreadystatechange
event that gets triggered by an xhr.send(), and the events handed
to .dispatchEvent(event).
--
Jorge.
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      06-28-2010
In comp.lang.javascript message <(E-Mail Removed)>,
Sun, 27 Jun 2010 11:16:59, Thomas 'PointedEars' Lahn
<(E-Mail Removed)> posted:

> And this is not a support forum, so nothing for
>you to probe, but a lot for you to learn. Learn to read and to ask smart
>questions to begin with.


<FAQENTRY> An entry on Pointy-Head is needed, to explain the peculiar
nature of his personality and the general invalidity of such of his
opinions as are not traceable to ECMA-262.

--
(c) John Stockton, nr London UK. ??@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
In MS OE, choose Tools, Options, Send; select Plain Text for News and E-mail.
Don't quote more than is needed, and respond after each quoted part.
 
Reply With Quote
 
Bwig Zomberi
Guest
Posts: n/a
 
      06-29-2010
Dr J R Stockton wrote:
> In comp.lang.javascript message<(E-Mail Removed)>,
> Sun, 27 Jun 2010 11:16:59, Thomas 'PointedEars' Lahn
> <(E-Mail Removed)> posted:
>
>> And this is not a support forum, so nothing for
>> you to probe, but a lot for you to learn. Learn to read and to ask smart
>> questions to begin with.

>
> <FAQENTRY> An entry on Pointy-Head is needed, to explain the peculiar
> nature of his personality and the general invalidity of such of his
> opinions as are not traceable to ECMA-262.
>



It would be great if all CLJ regulars were covered and also mentioned
who generally picks on who. Maybe Garret could create a separate page
and link it in the FAQ.

--
Bwig Zomberi
 
Reply With Quote
 
Garrett Smith
Guest
Posts: n/a
 
      06-29-2010
On 2010-06-28 10:26 PM, Bwig Zomberi wrote:
> Dr J R Stockton wrote:
>> In comp.lang.javascript message<(E-Mail Removed)>,
>> Sun, 27 Jun 2010 11:16:59, Thomas 'PointedEars' Lahn
>> <(E-Mail Removed)> posted:
>>
>>> And this is not a support forum, so nothing for
>>> you to probe, but a lot for you to learn. Learn to read and to ask smart
>>> questions to begin with.

>>
>> <FAQENTRY> An entry on Pointy-Head is needed, to explain the peculiar
>> nature of his personality and the general invalidity of such of his
>> opinions as are not traceable to ECMA-262.
>>


It's easy to point out flaws in others but you do your fair share of
name-calling, and sometimes post occasional bible quotes.

>
>
> It would be great if all CLJ regulars were covered and also mentioned
> who generally picks on who. Maybe Garret could create a separate page
> and link it in the FAQ.
>


I've got better things to do with my time than figure out how to writ an
objective autobiographical synopsis of "PointedEars".

I'd rather see a document that inspires useful contribution and
productive discussion and discourages time-wasting and drama games. But
then, given a choice of what to do with my time, I'd rather focus just
on technical material.

The good thing about this NG is a double-edged sword: Anybody can say
anything.

To make a positive contribution, eliminate any name calling. Have a
positive attitude about making a useful contribution. You don't have to
write a bunch of niceties or anything.

A proposal to an FAQ entry is a good contribution (even though I
disagree with what was proposed that I am replying to). A technical code
review would be another great contribution. That is something I've been
working on, among other things, actually. When its done, I'd like to add
a link to it from the FAQ. And that, to me, seems more valuable and
worthwhile use of my time than writing about PointedEars.

Garrett
 
Reply With Quote
 
Bwig Zomberi
Guest
Posts: n/a
 
      06-29-2010
Garrett Smith wrote:
> On 2010-06-28 10:26 PM, Bwig Zomberi wrote:
>> Dr J R Stockton wrote:
>>> In comp.lang.javascript message<(E-Mail Removed)>,
>>> Sun, 27 Jun 2010 11:16:59, Thomas 'PointedEars' Lahn
>>> <(E-Mail Removed)> posted:
>>>
>>>> And this is not a support forum, so nothing for
>>>> you to probe, but a lot for you to learn. Learn to read and to ask
>>>> smart
>>>> questions to begin with.
>>>
>>> <FAQENTRY> An entry on Pointy-Head is needed, to explain the peculiar
>>> nature of his personality and the general invalidity of such of his
>>> opinions as are not traceable to ECMA-262.
>>>

>
> It's easy to point out flaws in others but you do your fair share of
> name-calling, and sometimes post occasional bible quotes.


True about namecalling. However, what he means as a joke is also
interpreted as an offensive sometimes.

>
>>
>>
>> It would be great if all CLJ regulars were covered and also mentioned
>> who generally picks on who. Maybe Garret could create a separate page
>> and link it in the FAQ.

>
> I've got better things to do with my time than figure out how to writ an
> objective autobiographical synopsis of "PointedEars".
>
> I'd rather see a document that inspires useful contribution and
> productive discussion and discourages time-wasting and drama games. But
> then, given a choice of what to do with my time, I'd rather focus just
> on technical material.
>
> The good thing about this NG is a double-edged sword: Anybody can say
> anything.
>
> To make a positive contribution, eliminate any name calling. Have a
> positive attitude about making a useful contribution. You don't have to
> write a bunch of niceties or anything.
>
> A proposal to an FAQ entry is a good contribution (even though I
> disagree with what was proposed that I am replying to). A technical code
> review would be another great contribution. That is something I've been
> working on, among other things, actually. When its done, I'd like to add
> a link to it from the FAQ. And that, to me, seems more valuable and
> worthwhile use of my time than writing about PointedEars.
>


As many of them seemed to pick on you, I thought you have plenty to
provide. Being an FAQ maintainer seems like a thankless job. I have felt
that they may be jealous because you are the maintainer and not them.



--
Bwig Zomberi
 
Reply With Quote
 
Laurent vilday
Guest
Posts: n/a
 
      06-29-2010
Bwig Zomberi :
> It would be great if all CLJ regulars were covered and also mentioned
> who generally picks on who. Maybe Garret could create a separate page
> and link it in the FAQ.


OMG no ! Never ! Don't !

Do I really need to explain why such public files are horrible ?

--
laurent
 
Reply With Quote
 
Bwig Zomberi
Guest
Posts: n/a
 
      06-29-2010
Laurent vilday wrote:
> Bwig Zomberi :
>> It would be great if all CLJ regulars were covered and also mentioned
>> who generally picks on who. Maybe Garret could create a separate page
>> and link it in the FAQ.

>
> OMG no ! Never ! Don't !
>
> Do I really need to explain why such public files are horrible ?
>


After visiting this newsgroup, I learned a lot of things. David Mark's
feature detection, useful stuff on Stockton's website, special effects
JS on Jorge's website and thing like that. While they individually seem
smart, their general disposition towards each other sometimes borders on
anti-social.

--
Bwig Zomberi
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vertical padding on first-letter pseudo class /w gecko Jonathan N. Little HTML 1 11-02-2005 01:52 AM
Re: Class selector, ID selectors and link pseudo-classes Luigi Donatello Asero HTML 1 06-04-2005 06:58 PM
Class selector, ID selectors and link pseudo-classes Luigi Donatello Asero HTML 4 06-04-2005 05:02 PM
use javascript onmouseover to trigger hover state of another image Elisa Javascript 2 07-11-2004 12:25 AM
add window.status javascript to a:hover css pseudo-class? Bob P. Javascript 2 06-25-2004 05:51 PM



Advertisments