Write your first code in jQuery

The “$” sign you see in the code is jQuery object. The first part “$(document)” selects the document and binds it with ready event using a jQuery method “.ready()”, which further calls an anonymous function “function() {}” for executing further statements.

Image

Similarly, the inner code “$(“body”).html(“<h1>Life is awesome!</h1>”);” does the same thing. Here “body” is a selector and “.html” is a method to write HTML into the body tag. However, I’m not calling any anonymous function here though I could if necessary.

FAQ

Q. What is a selector?
Selector selects the specific element from the DOM (Document Object Model). You can see that selector code is very similar to CSS. This is the beauty of jQeury, it leverages on your current knowledge of CSS.
Q. What is an Anonymous function?
Anonymous function is called but not bound to any identifier. For more information click here.
Note: The source of this article has been taken from here.
Advertisements