$("something") selects some DOM element, right? Like elsewhere, where you have:
$("#changeMessage") // selects elem with id="changeMessage"
$(".quote") // selects elem with class="quote"
$("#tweetbutton") // selects elem with id="tweetbutton"
Notice that each of the selectors is a string wrapped in quotes. If you omit the quotes, I think jquery just freaks out. If you also omit the
$ and just use
message as a regular variable, the JS engine will scan the scope chain for a that variable. That variable needs to be a jQuery object in order to use the
.text() method (link):
var message = $("#msg");
.text() is a method (function) and needs the parentheses.
You don’t have a DOM element with ID “message”, but you do have “msg”. So you could technically do:
But you already have the quote in your JS - no need to re-capture it from the DOM.