A small jQuery doubt

Discussion in 'jQuery' started by srvijay, Jan 12, 2010.

  1. #1
    Hi,
    I just have a small doubt in jQuery..

    I have a js file, sampleFunc.js, which has this code:
    I'm calling this js from my html file like this:

    All I need is:
    1. Send a couple of parameters through sampleFunc and receive them at the JS file..

    Should I replace the $ in the "function($)" with the 2 parameter??

    Can someone help me?


    PS: Its the first time I'm seeing a jQuery script :) So please dont bother my silly doubts..
     
    srvijay, Jan 12, 2010 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    no. the (function($) { ... })(jQuery); is called a closure and is there to ensure that your function will play nicely if jquery goes into compatibility mode. it binds/aliases $ to jQuery for the scope only w/o affecting the global ownership of $

    passing parameters to the function needs to take place under the domready call to the function itself.
    
    $("#samp").sampleFunc(someArgs, arg2);
    
    Code (javascript):
    modify the function declaration in the .js file to nominate the arguments and do whatever needs to be done with them, just as usual.
     
    dimitar christoff, Jan 13, 2010 IP
  3. srvijay

    srvijay Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Dimitar, for your reply.. Just tried out a few more things after going thro the official docs and the code is working fine.. :)

    Thanks again!
     
    srvijay, Jan 14, 2010 IP