Why does onclick event not cancel href navigation?

As far as I understand the HTML code:

    <a onclick="return confirm('Are you sure?');" href="http://news.bbc.co.uk">BBC</a>

should produce a HTML page with a single link that if clicked asks "Are you sure" and then if you press Cancel the link will not fire. However, it goes to the link whether I press OK or Cancel.

Why does it do this and how can I get the click to cancel?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I copied exactly what you posted and it works as expected. There's nothing wrong with it. Make sure your page doesn't have a typo.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BOITAuthor Commented:
Thank you, you are correct, the code if fine.

the problem was with the browser. I had javascript enabled - the confirm message was displaying - but the navigation occured whichever button was pressed.

I did a full reset on Internet Explorer - lost all saved passwords - the lot. The code now works correctly.

Thanks for pointing me in the right direction - I was pulling my hair out!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.