I'm using jquery in a greasemonkey user script. I'm trying to add a bunch of options to a select based on an array and also stick the corresponding object in the element with jquery.data like this:
$.each(some_array, function(item){
// These next 2 statements seem awkward to me and I was also hoping
// a jquery master could show me a slicker way to perhaps
// combine them into something simpler
$('select').append('<option>dummy</option>');
$('select option:last-child').data('obj', item);
});
Then I'd like to get the object back out on selection:
$('select').change(function(){
var theObj = $('option:selected', this).data('obj');
});
However in my greasemonkey user script, theObj is undefined. I know there's some monkey business going on with wrappers, unsafeWindow etc. I was just hoping somebody might know what exactly makes this not work.