Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Another way to write this? (http://www.velocityreviews.com/forums/t943283-another-way-to-write-this.html)

laredotornado 09-06-2011 06:52 PM

Another way to write this?
 
Hi,

I have this JS ...

if(img[i].alt == 'Yes')
img[i].click();

Is there anotehr way to write the "img[i].click()" clause that doesn't
use the "click()" action but achieves the same thing? Thanks, - Dave

Jukka K. Korpela 09-06-2011 07:08 PM

Re: Another way to write this?
 
6.9.2011 21:52, laredotornado wrote:

> if(img[i].alt == 'Yes')
> img[i].click();


What might be the idea behind that?

> Is there anotehr way to write the "img[i].click()" clause that doesn't
> use the "click()" action but achieves the same thing?


You seem to ask how to eat your cake without eating your cake.

On the other hand, by default, clicking on an image has no effect, so
there is no "same thing" to be achieved. And if you have assigned an
onclick handler to an image, then you could just call that handler
instead of using the event.

What's the real problem you're trying to solve?

--
Yucca, http://www.cs.tut.fi/~jkorpela/

dhtml 09-08-2011 05:39 AM

Re: Another way to write this?
 
On Sep 6, 12:08*pm, "Jukka K. Korpela" <jkorp...@cs.tut.fi> wrote:
> 6.9.2011 21:52, laredotornado wrote:
> > if(img[i].alt == 'Yes')
> > * * *img[i].click();

>
> What might be the idea behind that?
>
> > Is there anotehr way to write the "img[i].click()" clause that doesn't
> > use the "click()" action but achieves the same thing?

>
> You seem to ask how to eat your cake without eating your cake.
>
> On the other hand, by default, clicking on an image has no effect,


Clicking on the IMG has the effect of calling any registered handlers
on that element.

Calling a "click" method on the IMG, where supported, will cause an
event to be fired at that object and unless propagation is stopped, it
will bubble.

so
> there is no "same thing" to be achieved. And if you have assigned an
> onclick handler to an image, then you could just call that handler
> instead of using the event.
>

That's going to add complexity with the `event` parameter (or
`window.event`). I'd avoid doing that.

> What's the real problem you're trying to solve?
>

That's the right question right there. Describe the goal, not the
step:
http://catb.org/~esr/faqs/smart-questions.html#goal
--
Garrett


All times are GMT. The time now is 04:27 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.