Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

How to pass arguments to jquery function

jQuery jquery

  • Please log in to reply
1 reply to this topic

#1 thatsme


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 218 posts

Posted 14 September 2012 - 03:46 AM

Hi. I googled but i can't figure out how to pass arguments to jquery functions. I think it would be helpful if someone rewrite this code in jquery style
<div onclick="javascript:sum('1', '2')"></div>
<div onclick="javascript:sum('5', '7')"></div>

function sum(a, <img src='http://img.codecall.net/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />{
    var sum = a+b

  • 0

#2 Vaielab


    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts
  • Location:Quebec City
  • Programming Language:Java, C++, C#, PHP, JavaScript, Visual Basic .NET, Transact-SQL, ActionScript

Posted 14 September 2012 - 04:12 AM

The sum function can hardly be converted in JQuery.
One of the main aspect of JQuery is to wrap html element, and since the sum function don't use any html element, there is no need to make a JQuery function from it.
But most JQuery use a json style way to pass element like this
  varName1: value1,
  varName2: value2,
  varName3: value3

But this is only one way, since JQuery is still javascript, passing 2 parameter just like on your example is a good way too
  • 0

You can now stalk me on linkedin: http://ca.linkedin.c...elle/24/b44/88/ !

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download