Browse files

Merge pull request #176 from ymendel/jquery_v_js_color

make the JavaScript and jQuery examples agree on the color
  • Loading branch information...
2 parents be4fc8f + 23d2a6b commit 2a69b7ab0d85cdcd344bdcf21339945aa224aa13 @tjgrathwell tjgrathwell committed Mar 31, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 sites/frontend/jquery_vs_javascript.step
2 sites/frontend/jquery_vs_javascript.step
@@ -13,7 +13,7 @@ steps do
step do
message "Underneath the lines you just commented out, let's take a shot at writing the same functionality in straight JavaScript. There are a number of elegant ways to do this; here's one that's not elegant, but it's short:"
- source_code "js", "document.getElementById('copyright').onclick = function () { \n\s\s = 'red';\n}"
+ source_code "js", "document.getElementById('copyright').onclick = function () { \n\s\s = 'purple';\n}"
message "If you save the page, refresh, and click, you should see the same visual result (purple text), but this isn't a great approach for a couple of reasons. Not only is this more typing, and harder to read, it's also easily breakable. (You can only set an element's onclick attribute to one thing, so it might get overwritten by another script on the page and not work later!) jQuery works in a different way, by listening for events, so different functions can all be listening for the same event, and you can add a new response to an event without worrying about overwriting an existing one."

0 comments on commit 2a69b7a

Please sign in to comment.