Uncaught TypeError: Cannot create property 'guid' on string '

21,118

Solution 1

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/

Solution 2

Do you want to invoke function displayGIF with parameter 10 or 20 based on click on dbclick. If that is the case then you can write

  $(".topic-btn").on("click", function(){
                                        displayGIF(10);
                                        });
Share:
21,118

Related videos on Youtube

A. Andersen
Author by

A. Andersen

I am an aspiring web developer with a lot of questions and a lot to learn.

Updated on October 16, 2020

Comments

  • A. Andersen
    A. Andersen over 3 years

    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.

    • Tushar
      Tushar over 5 years
      displayGIF() is called immediately. Use , function() { displayGIF(10) } syntax.
    • Suresh
      Suresh over 5 years
      $(document).on("click", ".topic-btn", function(){ displayGIF(10); });or else $(".topic-btn").on("click", function(){ displayGIF(10); })