I am creating a user control that will create a series of html elements dynamically. Some of these controls will be database-driven cascading drop-downs. I’ve seen the JQuery .data() method suggested and used in examples for storing additional data about controls, but I don’t know how to implement it on dynamically created elements.
I’m adding elements this way:
new LiteralControl(@"<select onchange=""DoSomething()""></select>")
So, how do I go about using .data() on these newly created elements so that the additional data is stored when they’re created? I wanted to use custom attributes, but I gather that’s not widely supported and can be problematic in legacy browsers.
I am very new to web stuff, so by all means if I didn’t explain something well, let me know.
If you know which data the elements should store by the time you are creating those elements, you could use
data-*attributes.