O'Reilly logo

PhoneGap by Andrew Lunny

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – Simple logging and error checking

Let's add a second button to You Are The Best with some new social behavior, and see what to do when things go wrong:

  1. Open index.html in your text editor of choice, and add our second button immediately below the first:
    <button id="likeMe">Tell me I’m great</button><br>
    <button id="likeHer">Tell her I'm great</button>
  2. Let's open the page in Safari to verify that it renders as expected:
    Time for action – Simple logging and error checking
  3. Now let's add some behavior for our new button. We'll rewrite the JavaScript as follows (changes are highlighted):
    function alertCompliment() {
      var elementId = this.id,
      var greeting;
      if (elementId) {
     greeting = "you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required