X

LATEST #JQUERY NEWS

jQuery’s .click() Method


With jQuery, it’s super easy to make something happen as a result of something else being clicked using the .click() method. All you need to do is pass a function through the .click() method. The .click() method will be the trigger event (make sure you use a selector to indicate which HTML element being clicked should trigger your code), and the code within the function that you’ll pass through the .click() method will execute the result of the click trigger. For example, maybe you want to remove a particular element once it’s clicked on. Your code would look like this:

$(".bye").click(function(){
$(this).remove();
})

By passing a function through the click method, you’re instructing the code to make sure you remove the $(“.bye”) element when it is clicked on. With jQuery, the possibilities are endless for the kind of action you want to occur after the .click() trigger is activated. You could toggle something, make it fade in or out, make it slide up or down, trigger an alert message…anything you can dream of, you can probably make it happen with a little (or a lot of) jQuery.

Let’s do one more example. In the code below, you’ll see that when the HTML element is clicked, another element will execute a .slideUp() animation:

$(“.click-me").click(function(){
$(“#menu”).slideUp();
})

Recently Published

Screen Shot 2017-04-23 at 10.15.41 AM
»

How to Use jQuery to Create a Sticky Navigation on Scroll

Creating “sticky” elements is something that can often be ...

article image
»

How to Use jQuery’s Keystroke Methods

jQuery has a few built-in keystroke methods that are all triggered by ...

article image
»

How to Change iFrame Styling Using jQuery

If you’ve ever had the displeasure of working with iFrames, ...

article image
»

How to Use jQuery to Create Blinking Text

Blinking text is one of those cool features that you never actively ...

article image
»

Convert Images to Black and White using jQuery

Converting an image to black and white is no longer a manual event. ...

article image
»

How to Disable Right-Click Menu Using jQuery

There can be dozens of reasons why you may want to disable right ...

article image
»

How to Optimize jQuery Code for Better Performance

jQuery is the most popular client side library, in fact almost every ...

article image
»

Using Head.js to Load All Your JavaScript

In the past few years, client side frameworks/libraries have become ...

article image
»

How to Detect Browser Using jQuery

One of the more frustrating parts of creating a new web project is ...