tags:

views:

45

answers:

2

I am doing the following :

$(function() {
    var $txt = $("#text1");

    callMe($txt, $txt.val());                


});

function callMe(t, vlue) {
    t.html(vlue)
}

I will be calling the callMe() function multiple times.

Is it Ok to do the way i have shown or is there a better way?

+6  A: 

There's no problem with passing jQuery objects around.

It will be much more efficient than re-running the selector each time - that's for sure.

Greg
If all your code is jQuery, I think it's good design.
powtac
+2  A: 

jQuery is JavaScript. And this is absolutely valid in JavaScript. You can even just pass the jQuery object an do this:

function callMe(t) {
    t.html(t.val());
}
Gumbo