Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery.globalEval() method

jQuery.globalEval() method

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods

Example

Execute a script in the global context

var

name

=

"

Global Variables

"

; $

(

function

(

)

{

function

test

(

)

{

var

name

=

"

local variables

"

;

alert

(

name

)

;

//

local variables

eval

(

"

alert(name);

"

)

;

//

local variables

$.

globalEval

(

"

alert(name);

"

)

;

//

Global Variables

}

test

(

)

;

}

)

Try it »


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. The difference is that jQuery.globalEval() executes code in the global scope.


Syntax

$

.globalEval( code )

Parameters Description
code String type: The specified JavaScript code string to run.

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods