$("#recaptcha_widget img").one('load',function(){ $("#recaptcha_widget img").addClass('largecap'); $('#recaptcha_image').css('height', '62px'); });
This will only listen to once in the load event of the image, which you reload and then execute the following code.
I used .one() instead of .load() here because you do not want to attach a new listener every time you call reloadCAP()
Edit
Well, thatβs what I think is the problem. When you call Recaptcha.reload() , it removes <img /> and replaces it with a new one. Therefore, when we try to attach an event, it is deleted as the image is deleted.
What you need to do is put the largecap class in the largecap div and change your css style to look like
.largecap img { height: whatever; width: whatever; }
source share