zacran
zacran

Reputation: 865

Dynamically Add Multiple Jquery Functions

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

Answers (1)

Barmar
Barmar

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

Related Questions