user1472878
user1472878

Reputation:

jquery onclick event doesn't work

This script doesn't work.. Where is the error? With .onload it's OK

$(document).ready(function() {

var img = new Image();
img.onClick = function() {
$("div").animate({width:this.width, height:this.height});
}
img.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';
});

thanks for the aid.

Upvotes: 0

Views: 700

Answers (3)

palaѕн
palaѕн

Reputation: 73966

Try this:

var img = new Image();
img.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';

$(img).live("click", function() {
    $("div").animate({
        width: $(this).width(),
        height: $(this).height()
    }, 1000);
}).appendTo('body');​

Upvotes: 0

jhummel
jhummel

Reputation: 1764

Since you're using jQuery anyway, why not just stick with it:

$(function(){  // this is a shortcut for $(document).ready
   var img = $('<img src="http://www.google.com/intl/en_ALL/images/logo.gif>');
   img.on('click', function(){
     $('div').animate(...)
   })
   img.appendTo('body')
})

Upvotes: 1

Musa
Musa

Reputation: 97717

Its .onclick not .onClick, javascript is case sensitive.

Upvotes: 3

Related Questions