Assign numbered ID to dynamically created Element of selectable Grid by "Yair even or"

51 Views Asked by At

I want to assign an ID to every Element(.grid__area) that gets created by the user. For Example: area1, area2 and so on. Problem is that I can't figure out where to place it correctly.

Codepen: https://codepen.io/vsync/pen/ONWmmq

I've tried to locate the moment where the element gets created and via

.attr('id','area'+count+'')

to assign the new id.

this.DOM.scope.append( selectionArea ); // Line 242
console.log('Created!');

But I can't trigger this nor I can't place it in the area template section.

Thanks for any help.

1

There are 1 best solutions below

0
On BEST ANSWER

Add this line before line 242 (demo):

selectionArea.attr('id','area'+count++);

Don't forget to include the counter variable in the grid.