<button onclick="setBackgroundColor('000AAA')">Set Color</button>
Well, try it and you will see the action.
Next, to achieve the similar functionality, we will use a Jquery.
Look at the difference. Now let me ask you a question which one is neat? And which one you will prefer? Of course, we all know that jquery is much simple, neat and easy to handle.
Well, How Was This Possible?
Why Jquery and Not Others?
There are other frameworks also available so why jquery, because it is very popular and is growing daily with lot of new tasks being added to the library. One of the major factors is that it is being used by almost all the big companies.
What are the Prerequisites?
This is an important question as, if you know things like:
Then half of the battle is won.
How Can I Start?
Go and download the latest jquery from jquery.com and add it into the folder where you are developing your application.
There are two versions of jquery available:
- Production Version - Download this version, if you are new to jquery
- Development version
If you do not want to download, then also there is a way to include jquery in your project. There is a copy of jquery available on Google and Microsoft network, hosted on their CDN. You have to include this code in your page to include the library in your project.
The ‘$’ Syntax
We have our library in place, we will start with declaring ‘
$’. This is a shortcut for
Why It Is Required?
$(document).ready, we made sure that no jQuery code is run before the document gets loaded.
To manipulate any element of the page, we would first have to select the element and for that, jquery has provided us with few selectors.
$(*) - Selects all elements
$(p) - Selects all paragraph elements
$(div) - Selects all
I have provided only 3 examples, which can be used to start your learning. There are many varieties available and many others, you will learn through practice.
$(#ID) - Selects the element having id mentioned after
$(#label1) - Selects the label having
ID as ‘
$(.classname) - Selects all elements having CSS class name mentioned after ‘
$(.headercss) - Selects all elements with CSS class name as
Now we know how to select the elements, start some operation on them to gain more clarity.
Explanation: It will select button with id ‘
btn’ and on click event of the button, function will be called which will hide all the
div elements and show all the elements having CSS class as ‘
There is one click event mentioned in the above example.There are many other user actions which are ‘
focus’, etc. These events are attached to our elements and can be called by any user action. We have covered the basics here so in the next article, we will dive deep into Jquery.
- Web-Page responses by PostBack, AutoPostBack, CrossPostBack, CallBack