Another way to write this?

L

laredotornado

Hi,

I have this JS ...

if(img.alt == 'Yes')
img.click();

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

Jukka K. Korpela

if(img.alt == 'Yes')
img.click();


What might be the idea behind that?
Is there anotehr way to write the "img.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?
 
D

dhtml

if(img.alt == 'Yes')
     img.click();


What might be the idea behind that?
Is there anotehr way to write the "img.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top