Forum Moderators: open

Message Too Old, No Replies

help converting small jQuery code snippit to 'normal javascript'

YES, you read it right. I cant use jQuery for this example.

         

dragon master mokuba

6:02 am on Apr 29, 2010 (gmt 0)

10+ Year Member



Here is the snippet.

$("input").mousedown(function(e){ alert(e.which) });


I need it to be 'normal javascript', something like this:

document.getElementsByTagName('input').onmousedown = function(e){ alert(e.which); };


How would I get this accomplished?

Note:
I CANNOT add an onmousedown attribute to the input element.

Thanks :)

daveVk

6:35 am on Apr 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If there is a single input element then

document.getElementsByTagName('input')[0].onmousedown = function(e){ alert(e.which); };

else loop thru each

els = document.getElementsByTagName('input');