jQuery how to access JavaScript variable
I know this is a very simple (rather stupid) quesiton
I have a javascript array chart["Ref"]
how would access it in Jquery
can you access javascript variables from jquery and vice versa.
Yes I know jquery is J开发者_开发问答avaScript still ;-)
You access it normally. jQuery is still JavaScript, fancy JavaScript, but JavaScript. You can access any and all variables normally within jQuery.
Of course, variable scope rules apply here.
What do you want to do with the array??
you could loop it with:
$.each(chart, function() {
//your code here, you could access to the current element with "this"
});
Just access it normally.
chart["Ref"]
It's still only javascript
If scope allows you can access any variable on the page.
You answered your own question. jQuery *is* Javascript.
So yes, you can access other non-jQuery object variables (provided the variable is in scope, as others have pointed out).
If you'd like to call jQuery functions on your array (like each
, for example) you can do that as well:
$(chart).each(function(idx, obj) {
// do stuff
});
精彩评论