Thomas
Thomas

Reputation: 34188

JQuery and Dynamic javascript execute

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.

Upvotes: 1

Views: 626

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

You could use the eval function. Example:

var someCommand = 'alert($("#txtName").val());';
eval(someCommand);

Upvotes: 4

Related Questions