views:

16

answers:

2

Hello,
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 confused 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.

+3  A: 

$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')
Keeper
Oh i see, means `$tabs` is just a normal javascript variable, not a jQuery binded variable?
JustLearn
Yes, don't be confused about `$`: it's just a character. That code could also have been like this `var tabs = $('#example').tabs()` I guess prefixing variables whose value is a jquery object with `$` is just a reminder for the developer ;)
Keeper
A: 

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 http://stackoverflow.com/questions/3155979/why-does-several-javascript-libraries-use-for-one-or-other-use for wonderful explanation of why $ is used in javascript or jQuery.

sushil bharwani
Thank you for the link Sushil
JustLearn