Easy Tutorial
❮ Misc Pushstack Sel Lastoftype ❯

jQuery.globalEval() Method

jQuery Miscellaneous Methods

Example

Execute script in the 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();
})

Definition and Usage

The jQuery.globalEval() function is used to execute a piece of JavaScript code globally.

Tip: This function is similar to the regular JavaScript eval() function. However, jQuery.globalEval() executes the code in the global scope.


Syntax

Parameter Description
code String type The JavaScript code string that needs to be executed.

jQuery Miscellaneous Methods

❮ Misc Pushstack Sel Lastoftype ❯