jQuery globalEval() method

The globalEval() method in jQuery is used to globally execute some JavaScript code. This method is different from JavaScript's eval() method, as the globalEval() method executes within the global context.

Syntax

The commonly used syntax of using the globalEval() method is given as follows -

This method accepts some parameters that are defined as follows -

code: It is optional that specifies some JavaScript code to be executed. It is of string type.

options: It is of PlainObject type.

nonce: It is of string type. It is the nonce attribute passed to the executed script.

doc: It is of the document type. It is a document in which context the code will be evaluated.

Now, let's see an illustration to understand the use of the globalEval() method.

Example

It is a simple example of using the globalEval() method. In this example, we are using the globalEval() method to execute the script in a global context.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery globalEval() method

After clicking the given button, the output will be -

jQuery globalEval() method




Latest Courses