Assigning data to an <li> element?
Posted
by user246114
on Stack Overflow
See other posts from Stack Overflow
or by user246114
Published on 2010-06-13T22:42:53Z
Indexed on
2010/06/13
22:52 UTC
Read the original article
Hit count: 169
jQuery
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
© Stack Overflow or respective owner