Why must I define a variable outside a javascript function definition? (jQuery / #anchor question) -


I am writing a jQuery function, depending on the details of the current # of the page. I'm using the jQuery URL Parser plugin to get anchor.

  $ .fn.vtabs = function () {Warning ("Your anchor is" + $. Url.attr ('anchor')); }  

This code gives me the interval "#nav" (I use #NU in some of my links) I can type "# shipping" in the browser bar in endless time I'll click on this page on URL, which uses different anchors, but this code always gives me "# NAV".

I changed my problem to code:

  var current_anchor = $ .url.attr ('anchor'); $ .fn.vtabs = function () {warnings ("your anchor" + current_changer); }  

Now it always gives me the correct anchor but why I do not know, and it appears that the variables defined outside of that function are misguided.

It seems that some caching may be turned on with that plugin, why not leave the plugin and anchor Just use window.location.hash to get it?


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -