Another way to write this?

Discussion in 'Javascript' started by laredotornado, Sep 6, 2011.

  1. 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
     
    laredotornado, Sep 6, 2011
    #1
    1. Advertising

  2. 6.9.2011 21:52, laredotornado wrote:

    > 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?

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Sep 6, 2011
    #2
    1. Advertising

  3. laredotornado

    dhtml Guest

    On Sep 6, 12:08 pm, "Jukka K. Korpela" <> wrote:
    > 6.9.2011 21:52, laredotornado wrote:
    > > 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
    --
    Garrett
     
    dhtml, Sep 8, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ding
    Replies:
    1
    Views:
    535
    Andrew Thompson
    Jul 1, 2004
  2. =?Utf-8?B?QWJlbCBDaGFu?=
    Replies:
    6
    Views:
    9,531
    Rahul
    May 3, 2006
  3. Eddy Xu
    Replies:
    5
    Views:
    142
    Eddy Xu
    Apr 11, 2008
  4. Mikko Tussunen

    Best way to write to another frame?

    Mikko Tussunen, Oct 4, 2003, in forum: Javascript
    Replies:
    1
    Views:
    124
    Lasse Reichstein Nielsen
    Oct 4, 2003
  5. francisco lopez
    Replies:
    2
    Views:
    188
    Dr John Stockton
    Dec 31, 2004
Loading...

Share This Page