Contents
- TheElement
Guide
Page List
Copyright 2020 by McGraw-Hill Education (Publisher). All rights reserved. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher, with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication.
ISBN: 978-1-26-045769-8
MHID: 1-26-045769-9
The material in this eBook also appears in the print version of this title: ISBN: 978-1-26-045768-1, MHID: 1-26-045768-0.
eBook conversion by codeMantra
Version 1.0
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps.
McGraw-Hill Education eBooks are available at special quantity discounts to use as premiums and sales promotions or for use in corporate training programs. To contact a representative, please visit the Contact Us page at www.mhprofessional.com.
Oracle and Java are registered trademarks of Oracle Corporation and/or its affiliates. All other trademarks are the property of their respective owners, and McGraw-Hill Education makes no claim of ownership by the mention of products that contain these marks.
Screen displays of copyrighted Oracle software programs have been reproduced herein with the permission of Oracle Corporation and/or its affiliates.
Information has been obtained by Publisher from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, Publisher, or others, Publisher does not guarantee to the accuracy, adequacy, or completeness of any information included in this work and is not responsible for any errors or omissions or the results obtained from the use of such information.
TERMS OF USE
This is a copyrighted work and McGraw-Hill Education and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill Educations prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms.
THE WORK IS PROVIDED AS IS. McGRAW-HILL EDUCATION AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill Education and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill Education nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill Education has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill Education and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise.
To my wife, Heather, and children, Eva, Elizabeth, Elaine, and Evan, Bruce and Joy Anderson, and Dr. J. D. and Linda Andrews
In memory of John and Betty Hopkins, James D. and Livian Anderson, John William and Edith Hopkins, Burley T. and Aline Price, Doc Flores, and Clifton Idom
About the Author
John Pollock is employed as a software developer during the day and works on Web sites and other projects during the evening. You can find him on Twitter (@ScripttheWeb) or LinkedIn (https://www.linkedin.com/in/john-pollock-82a2b074). John holds a Bachelor of Arts in English from Sam Houston State University and currently lives in New Waverly, Texas with his wife, Heather, and children, Eva, Elizabeth, Elaine, and Evan.
About the Technical Editor
Christie Sorenson is a senior software engineer at ZingChart. She has worked on JavaScript-based systems since 1997 and has been fascinated with the evolution of the language. She has collaborated and been the technical editor on several JavaScript and HTML books. She holds a Bachelor of Science in Computer Science from University of California, San Diego, and now lives in San Francisco with her husband, Luke, and daughters, Ali and Keira.
Contents
TheElement
Acknowledgments
I would like to begin by thanking my wonderful wife, Heather Pollock, for all of her love, support, and encouragement in all I do. I love you! I would also like to thank my three daughters, Eva, Elizabeth, and Elaine, as well as my son, Evan. I love all of you!
I would like to thank my parents, Bruce and Joy Anderson, for their love and guidance, and for always supporting my endeavors.
I would like to thank Dr. J. D. and Linda Andrews for their love, guidance, and support.
In addition, I would like to thank Richard Pollock (brother) and family, Misty Castleman (sister) and family, Warren Anderson (brother) and family, Jon Andrews (brother) and family, Lisa and Julian Owens (aunt/uncle) and family, and every aunt, uncle, cousin, or other relation in my family. All of you have been a great influence in my life.
I would like to thank all of my editors at McGraw-Hill for their outstanding help and support throughout the writing of this book. Thanks to Lisa McClain, Emily Walters, Claire Yee, Snehil Sharma, Sarika Gupta, Bart Reed, and to all the editors who worked on this and previous editions of the book.
Thanks to my technical editor, Christie Sorenson, for editing and checking over all the technical aspects of the book and for helping me provide clear explanations of the topics that are covered.
I would like to thank God for the ability He has given me to help and teach people by my writing. In all your ways acknowledge Him, and He shall direct your paths. (Proverbs 3:6)
Introduction
W elcome to JavaScript: A Beginners Guide, Fifth Edition! Years ago, I was surfing the Web and noticed that people were publishing pages about themselves and calling them homepages. After viewing a number of these, I decided to create a homepage myself. I had no idea where to begin, but through trial and error I figured out how to code HTML and publish my documents on a Web server. Over time, I saw some interesting effects used on other homepages (like alert messages that popped up out of nowhere or images that would magically change when I moved my mouse over them). I was curious and just