Reputation: 865
Let's say I have a for loop dynamically generating Jquery functions - like so:
function addJqueryFunctions(divListJSON) {
for(var i in divListJSON)
{
var id = divListJSON[i].id;
$('#' + id + ').magicfunction();
}
}
How do I make it so that the Jquery functions generated in the for loop make it to the page and are run?
Upvotes: 0
Views: 40
Reputation: 780808
To select an element by ID, you need to prefix it with #
$('#' + id).magicFunction();
Notice that the variable and +
operator have to be outside the quotes.
Upvotes: 1