-1

Can someone please explain why am I not getting this alert message when clicked on the button? I just started learning HTML and this is the code given in my book which is supposed to work but it is not working when i execute it. What is the problem? I am using Mozilla Firefox Beta version.

<?xml version="1.0" encoding="UTF-8"?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>This is a test page</title>
</head>
<body>
    <h1>This is a test Paragraph</h1>
    <button type="button"
    onclick="alert('You've clicked me.')">Click me!</button>
</body>

3
  • the book you are using may be outdated. For html5 you can start your html file by using <!DOCTYPE html><html>... the <?xml tag you are using is not needed. hope that makes some sense. Commented Jan 9, 2013 at 8:34
  • Yes it does make sense. I'll find an updated article online to study from as I can't afford to buy another book. Any suggestion's for free tutorials would really be appreciated. Commented Jan 9, 2013 at 8:41
  • the book you have will be a great starting point. Then its simply a matter of looking at the page source of other sites and seeing what you can implement yourself. Hopefully your book also introduces CSS,.. w3.org has all the HTML information you could ever need, but is quite technical. I would recommend w3schools, but then other users would probably get upset! It's useful for tag references however. Commented Jan 9, 2013 at 8:49

2 Answers 2

6

You have a syntax error. You need to escape the apostrophe in "you've".

alert('You\'ve clicked me.')
Sign up to request clarification or add additional context in comments.

Comments

3

You need to change line

onclick="alert('You've clicked me.')">Click me!</button>

to

onclick="alert('You\'ve clicked me.')">Click me!</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.