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.


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.


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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s