开发者

How to change all $ to jQuery where some variable name starts from $ in some Jquery Plugin?

I learned from this article that to avoid confliction between javascript libraries, use jQuery.noConflict(); function just before jQuery(document).ready ( function () { }) and replace jQuery at all instance of $

but i have seen many jQuery plugin where $ is used with variable declaration???

here is an example on this link on below section

  How to...
  [edit]
  ...retrieve the index of the currently selected tab

   var $tabs = $('#example').tabs();
   var selected = $tabs.tabs('option', 'selected'); // => 0

now i m really c开发者_运维技巧onfused how to replace $ with jQuery in var $tabs??

first of all tell me how can we use jQuery instead of $ in above example and

what is the logic behind declaring variable starting with $ in javascript?? ( although this is a PHP varaible decalarion syntax)

Thank you.


$tabs is just a variable name. That's because javascript accepts a $ as part of a variable. You can also use variables like my$var = 10 or my$other$var$ = 20.

To use jQueryinstead of $ just substitute it in your code:

var x = $('#mydiv')

becomes

var x = jQuery('#mydiv')


JavaScript variable names start with a letter, $, or underscore.

http://javascript.about.com/od/variablesandoperators/a/vop04.htm

so $tabs is a normal variable and has nothing to do with jQuery.

Like javascript many other languages allow usage of $ in variable names.

You can refer this answer why does several javascript libraries use $ for one or other use for wonderful explanation of why $ is used in javascript or jQuery.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜