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

article image
»

7 Responsive jQuery Dropdown Menu Plugins

Dropdown Menu Plugins Dropdown menus are mostly used for website ...

article image
»

20 Stylish and Modern jQuery Tooltip Plugins

jQuery Tooltip Plugins Tooltips are a great option for showing extra ...

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...