Assigning data to an <li> element?
- by user246114
Hi,
I am generating some list items as a result of a search, and I want to attach some data to each list element from the search (possibly a bad idea to merge ui and data), but now curious about it. I am doing this:
var element = $("<li>Hello</li>);
element.mydata = "foo";
element.appendTo("#panelParent");
so I'm just assigning my stuff to element.mydata. My click handler reports that no such data exists for the element when clicked:
$('#panelParent').delegate('li', 'click', function() {
// this.mydata is undefined.
});
where did it go to? I could keep the data external to the a list item element, was wondering if there's a convenient way like this to just keep it bound though?
Thanks