开发者

Is it Ok to pass jquery objects to different functions?

I am doing the following :

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

开发者_StackOverflow    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?


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.


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());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜