To run and test the examples in this tutorial, you need to save them as html pages. You can use any text editor like notepad or anything convenient.
Ok, let’s use some basic functionality to test if we’ve done it right.
So, what happens here? Nothing special, we just show an alert with text ‘Works!!!’.
$ function is a factory method (shortcut) for the JQuery object.
With $(document).ready we register our code to the ready event of the document. The above code can be shortened:
Selectors and events
In JQuery an element can be selected in different ways – by id, by element type, by css class and so on.
This is a simple code showing how to use events and selectors:
The click(fn) binds a function to the click event of our matched element.
Let’s make our example a little more complex. We will count the clicks.