SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    328
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How do you put else condition on this function

    Hello,

    I have a function like this:
    Code:
    video.addEventListener("play", function(event) {
         // show image A
    });
    I want it to look like this:
    Code:
    if (play) {
    	show image A
    } else {
    	show image B
    }
    How would I achieve this?

    Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ketting00 View Post
    How would I achieve this?
    What would the value of play be, and how would you plan to set its value?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    328
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    It's just an example. I want to make an else statement to a function like this one and see if it possible. There should be other ways around but I has yet to discover it.

    Sorry, I'm confused at the moment, will ask again later after doing some experiments.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Is there some reason why simply wrapping the if/else inside the function wouldn't work?
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •