The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS jquery passing argument to functions?.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #298911


    What is the proper way to pass an argument to a function in jQuery?

    I want to pass a color to a function to update multiple css attributes

    I would think it would be something like below, but I can’t seem to get it to work.



    I can’t see why this would be any different from vanilla javascript. My best advice would be to start reading here and further.

    There is an exception for example when you do something like this: button.addEventListener('click', myFunction);, in that case the argument passed is the event.
    It’s jQuery equivalent would be something like this: $('button').on('click', myFunction);
    Passing an argument to that function would then be something like this: $('button').on('click', myFunction('test'));.
    And if you still want to have the event in your array of arguments you can do something like this: $('button').on('click', function (e) { myFunction(e, 'test') });


    I’m noticing a trend in these forums where a relevant question is posted, then after a reply it’s re-posted with links in, with the text “thanks my issue has been fixed”. I think these are fake questions with the sole goal to get people to click those links.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘CSS’ is closed to new topics and replies.