Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  167] [ 3]  / answers: 1 / hits: 28538  / 6 Years ago, tue, october 16, 2018, 12:00:00

I am a attempting to run the below jQuery .on() method with the parameter value of 10 however whenever I do I get an




Uncaught TypeError




 $(document).on(click, '.topic-btn', displayGIF(10));


It's my understanding that how it is written runs the function without a click event causing the error.



Is there a way around this? Ultimately, I want the .on(click... for a parameter value of 10 and a .on(dblcick... for a parameter value of 20.


More From » jquery

 Answers
38

You can change the code to this:



$(document).on(click, '.topic-btn', {'param': 10}, function(event){
displayGIF(event.data.param);
});


The data to on can be passed using the above method. Refer docs: http://api.jquery.com/on/


[#53314] Wednesday, October 10, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leifw

Total Points: 88
Total Questions: 103
Total Answers: 103

Location: France
Member since Thu, May 6, 2021
3 Years ago
leifw questions
;