1

Suppose one line or few lines of javascript is assigned to a variable. How could I execute it by jQuery.

Suppose alert($("#txtName").val());

The above code is assigned to a variable then how could I execute it by jQuery at run time.

kapa
78.9k21 gold badges167 silver badges179 bronze badges
asked Apr 19, 2011 at 6:10

1 Answer 1

4

You could use the eval function. Example:

var someCommand = 'alert($("#txtName").val());';
eval(someCommand);
answered Apr 19, 2011 at 6:11
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.