Jeremy nails the topic down with clear principles, examples that are easy to follow, and a fun but authoritative tone to his writing. I highly recommend this book to all web designers and developers.
Tips and tricks
These are some of the lessons I have noted:
- When considering JS for a project, or when writing scripts, a cautious, questioning attitude is desirable
(back slash) for escaping characters within a string
- Some naming conventions: camelCase for functions, under_score for variable names
- Good practice: use
varwhen assigning a value to a variable for the first time, especially within a function. This forces it to be local in scope
- Reminder for when manipulating the DOM: All nodes are objects
- For conditional statements,
if (something != null)can also just be
if (something)to shorten the statement
- The methods
setAttributeonly work on element nodes
- Here are some useful methods used on the document object:
- Instead of browser sniffing, use object detection:
if (!document.getElementsByTagName) return false;
Also, some of the wrong habits that I need to change:
- Using inline event handlers
- Relying on
innerHTMLfor modifying markup
onkeypressif possible, since
onclickworks with both mouse AND keyboard!
Worth it’s Weight
Visit the book’s companion web site and purchase the book on Amazon.com.
2 thoughts on “Learning DOM Scripting”
Hi there, thanks for featuring these simple but useful tips. Please keep them coming.