Reading Javascript & jQuery: The Missing Manuals was influential in several ways:
Then I attempted to do a simple .show() and .hide() (translation: hiding an element, then showing it upon a click) today with jQuery, and it didn’t work. Asked a co-worker who’s an experienced web developer, and he suggested I start using a debugger of some sort. He kindly linked me to Chrome Developer Tools, which showed me that there was a syntax error in the javascript.
What, you might ask, is a syntax error?
I did some googling, and some asking, and apparently the majority of syntax errors have to do with punctuation — such as forgetting to close a line with a semicolon, or forgetting parentheses.
I stared at the code. Stared some more. Then I finally had the bright idea to compare my code with another example of jquery that was working (I used this), and that was where I immediately saw that I was missing an entire set of closing parentheses });.
Whoops! Guess that I means I need to reread my book. Or just start practicing with some more examples.
My co-worker also pointed out the console.log(“comment about what your javascript is supposed to be doing here”) trick, which is achieved by putting that line above every piece of javascript you want to test, opening up browser tools, and then seeing if the line you typed runs in the browser console. He told me that it’s a good idea to get rid of these lines when the code goes live, though, because of compatibility issues with IE9.
Hurrah for super-helpful co-workers! Sometimes it’s good to have mentors who know their stuff. And to cross-check code with a working example rather than staring at it blindly, of course.
</span>