jQuery.globalEval() Method

Last Updated:

jQuery globalEval() Method

The jQuery globalEval() method executes some JavaScript code globally.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery globalEval() Method</h1> <button>Alert values</button> <script> $(document).ready(function(){ $("button").click(function(){ function myFunction(){ $.globalEval("var x = 5"); } myFunction(); alert("x = " +x); }); }); </script> </body> </html>

Syntax

$.globalEval(code);

Parameter Values

Value Type Explanation
code Optional Specifies the JavaScript code to execute.

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
$.globalEval()YesYesYesYesYesYesYesYesYesYesYesYesYes

Share this Page

Meet the Author