469,326 Members | 1,601 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

prototype property and onclick event

Hi,

as you know, if I attach a property to the object prototype, it will be attached to all objects from the same instance.

example :
if I have a couple of images inside a document such as :
<img src=""/>
<img src=""/>
<img src=""/>


I can say : document.images[0].prototype.printMessage = myFunction ;
where is :

function myFunction(){ alert('Hello'); }

now if I call : document.images[0].printMessage(), also
document.images[1].printMessage(), ... all of them will alert "Hello".

the question :

if I have a couple of anchors inside a document, can I say :

document.links[0].prototype.onclick = myFunction;


such as when I click on that anchor by the mouse, the function would be called ? .



thanks
Mar 27 '08 #1
2 5785
mrhoo
428 256MB
Try it out, but first see what is returned when you
alert(document.links[0].prototype)
Mar 27 '08 #2
Try it out, but first see what is returned when you
alert(document.links[0].prototype)
I think you are right, try using __proto__ instead of prototype .
I made a test case, its working, of course using the __proto__ .
document.images[0].__proto__.printMessage = myFunction ;
Mar 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Elf M. Sternberg | last post: by
10 posts views Thread by Robert | last post: by
19 posts views Thread by Joe | last post: by
6 posts views Thread by dennis.sprengers | last post: by
4 posts views Thread by reggiestyles | last post: by
3 posts views Thread by mike_solomon | last post: by
11 posts views Thread by webgour | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.