[RESOLVED]what am i doing wrong in trying to use the onmousedown with the following code?

I am trying to run a function everytime a user holds the mouse down on a div using the following. What am I doing wrong?

$(function () {          
	    $('div').onmousedown(function () {
	        $('div').each(function () {
	            id=$(this).attr('id');
	            alert(id);})
	    })
	})

A quick look at the jQuery docs will show that you used the wrong function name. Jquery does not use "on" in its event handler shortcut names.

One of the issues here is that you are using onmousedown instead of the
jQuery mousedown() function
:

$('div').mousedown(function () {
	$('div').each(function () {
           alert($(this).attr('id'));
        });
})

Thanks!

Leave a Reply