Assigning a Function result as a HTML ID

Viewed 121

So I'm creating an element dynamically like so:

 var el = $.parseHTML("<div><div class=\"content\" id=" + uniqueId + "><div/>");

And I'm generating a unique ID for each element:

var uniqueId = function () {
return 'id-' + Math.random().toString(36).substr(2, 16);
};

But on the output when the element is created the ID is literally "Function" ? How would I get the ID to assign the result of the function instead?

1 Answers

Call function instead of just providing it's name:

var el = $.parseHTML("<div><div class=\"content\" id=" + uniqueId() + "><div/>");
Related