Ad

Jquery How To Use Find() To Find The Variable Inside The Script Tag?

- 1 answer

I have the webpage with a <script> var nUos={//json} </script> how can i get that variable using find? Not sure if i can use that.

// if you are a Wordpress user I have a variable that is dynamic being passed to the WordPress pages using localize script functionality Please help

Ad

Answer

Assuming you are using wp_localize_script (something) like:

wp_localize_script('my-script', 'nUos', array('foo' => 'bar'));

nUos will be made available to you by means of the window object:

console.log(window.nUos)

//-> {foo: "bar"}

Sidenote: nUos is not JSON, it is a JS object literal.

Ad
source: stackoverflow.com
Ad