Hi Folks,
$(document).ready(function(){
var _new_li = $('<li/>', {
'id': 'p',
'text': 'CLICKME',
click: function(){
alert('fired');
},
data: {
'somedata': 'somedata',
}
});
_new_li.appendTo($("#example"));
});
I receive an "Uncaught TypeError: Cannot read property 'click' of undefined", when I try to click the element which I created like so. But, if you switch click: and data: it works.
$(document).ready(function(){
var _new_li = $('<li/>', {
'id': 'p',
'text': 'CLICKME',
data: {
'somedata': 'somedata',
},
click: function(){
alert('fired');
}
});
_new_li.appendTo($("#example"));
});
any explanation for that behavior?
Kind Regards
--Andy
PS:
I posted a similar behavior earlier in the jQuery Core Development forum, Mr. Swedberg answered there:
I'm pretty sure this is happening because you're setting data with an object, which >(until 1.4.2) would overwrite the event object. Not sure which version of jQuery you're >using in your project, but it looked like the jsbin example was using 1.4. Try upgrading >to 1.4.2 and see if that helps.
But it seems like the problem still exists in 1.4.2