jQuery.globalEval()Method
Examples
Execute script in global context
var name = "Global variable";
$(function () {
function test(){
var name = "Local variable";
alert(name); //Local variable
eval( "alert(name);" ); //Local variable
$.globalEval( "alert(name);" ); //Global variable
}
test();
})
Try it Yourself »
Definition and Usage
The jQuery.globalEval() function is used to execute a piece of JavaScript code globally.
Tip:This function works similarly to the regular JavaScript eval() function. The difference is that jQuery.globalEval() executes code in the global scope.
Syntax
$.globalEval( code )
| Parameter | Description |
|---|---|
| code | String type. Specifies the JavaScript code string to be executed. |
Other extensions
jQuery Miscellaneous Methods