How come the following does not work (attribute values are all 'undefined')
$(".item").wrap('<a href="' + $(this).attr("data-pid") + '.html"></a>');
but this code does?
$('.item').each(function(){
$(this).wrap('<a href="' + $(this).attr("data-pid") + '.html"></a>');
});
Thanks
thisis defined by the parent function, in your casethiswould be global window or whatever you have. If you create a functionthiswill be defined as the element you are targeting.