I have stored objects with name and price in javascript.
I’ve appended them in html with individual div for every object.
When I click the div, the background color changes, to denote that you have selected the object.
But how can I bind the onscreen divs to the javascript objects?
When the user clicks the div, I want that object’s ‘select’ property to turn to ‘true’.
Here is my code
Store the objects in an array.
When you create the div, give it an
idofsomething_something_array_index.You can extract the id from it with a regular expression,
split, etc.Alternatively, you can assign arbitrary properties to HTML Element objects, so you could just do:
Some people argue that this is convenient, some that adding non-standard properties risks future name space collisions.