Posts | Comments | Email

Using jQuery’s click event

In this tutorial we will be looking at jQuery’s click event. Remember the old onclick() stuff used with javascript? Well that’s dead, and jQuery’s click is the new king. Here is a snippet:

$(document).ready(function(){
    $('.clickable').click(function(){
        alert('hello');
    });
});

So how does it work you ask? Simple. In our jQuery ready block, we have a selector for the element with a class “clickable” (the element the click event is fired on), and our jQuery click function. Inside our click function we are simply alerting the word “hello”.

So when the user clicks on the element with the class “clickable”, an alert box will appear with the message hello. Simple stuff.

Share

Comments are closed.