Convert string to Javascript source code

Asked

Viewed 358 times

0

For example, if I have a string variable that stores "Alert('test');", how I can run it or convert it to source code?

1 answer

3


You can use the val() that evaluates(and executes) the code represented in a string. Example:

var comm = "alert('teste');";
eval(comm); //Executa o alert

Browser other questions tagged

You are not signed in. Login or sign up in order to post.