I have a string that contains a jquery command
How can I execute this string?
var myCommand = "$('#update').html('hello world!');";
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should not try to execute command from string, if you need to reuse them you should use a function:
and then call it
Otherwise you must use eval() but it’s not a best practice.
Or you could use globalEval() which is better since it doesn’t use eval()