I'm in day 1 of a learning java script MOOC.
We're looking at simple jQuery examples.
Right off there's something I don't understand.
An expression such as $("#xyz").html()
returns the text in the element. For example if
the corresponding html was <h1 name=xyz>hello world</h1>
, then $("#xyz").html()
evaluates to the string "hello world". I hope I understand this so far. And $("#xyz").html("new text")
sets the text to "new text"
so that the next call to $("#xyz").html()
returns "new text"
.
And, the expression $("#xyz").click(function (){42})
sets the click function to a function which will return 42
. However, the presenter of the course claims without explanation that $("#xyz").click()
calls the click function and returns 42
. I would expect that $("#xyz").click()
returns a function, not a number.
Am I confused? What's the logic here?