I am a bit confused about the usage of this and $(this).
Let's take the following example:
$('a.thmb')click( function() {
var img_url = $("img",this).attr("src");
$("#preview_img").attr( "src", img_url);
$("#preview_img").load( function(){
var pwidth = this.width;
var pheight = this.height;
//alert( $(this).width() ); // 0 <-- (1-1)
//alert( this.width ); //720 <-- (1-2)
$.fancybox({
....
onStart: function(){
//alert( $("#preview_img").width() ); // 0 <-- (2)
},
onComplete: function(){
//alert( $("#preview_img").width() ); //720 <-- (3)
}
});
//alert( $(this).width() ); //720 <-- (4)
});
}
- What is the difference between (1) ?
- What is the difference between (2) and (3)?
I want to know question 2. and the reason for difference (1-1) and (4)? just time?