Home > Web Front-end > JS Tutorial > body text

How to Pass Parameters in jQuery\'s .click Event Handler?

Barbara Streisand
Release: 2024-10-23 18:07:10
Original
290 people have browsed it

How to Pass Parameters in jQuery's .click Event Handler?

jQuery's .click: Passing Parameters to User Functions

Implementing parameter passing in jQuery's .click event handler can be challenging. Although you can call a function without parameters using .click(add_event), passing parameters requires an alternative approach.

Solution 1:

jQuery version 1.4.3 introduced a new feature that allows you to pass a data map to the event object. This map is made available to the event handler function as its first parameter. To utilize this approach, follow these steps:

// Code Template
$("selector").click({param1: "Hello", param2: "World"}, cool_function);

// Function Implementation
function cool_function(event){
    alert(event.data.param1);
    alert(event.data.param2);
}
Copy after login

The above is the detailed content of How to Pass Parameters in jQuery\'s .click Event Handler?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!