Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > Attaching event...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 36365 of 37128
Post > Topic >>

Attaching events to dynamically created elements

by shuchow@[EMAIL PROTECTED] Jul 24, 2008 at 09:35 AM

Hi, sorry for the basic question, but can someone explain to me some
basic event attachment process.  Say I have a function,
dynamicallyCreateElement(), that creates an element.  I want that new
element to have an onclick that calls another function.  So it looks
like this:

function dynamicallyCreateElement() {
....
element.onclick = myFunction;

....
}

function myFunction() {
...

};

The problem is that myFunction will be called during the execution of
dynamicallyCreateElement(), and not just the onclick for the element.

Instead, I have tod o this:


function dynamicallyCreateElement() {
....
element.onclick = function() { myFunctions())_;;

....
}

Why does the first one automatically execute myFunction, and what
exactly does
element.onclick = function() do?
 




 5 Posts in Topic:
Attaching events to dynamically created elements
shuchow@[EMAIL PROTECTED]  2008-07-24 09:35:02 
Re: Attaching events to dynamically created elements
SAM <stephanemoriaux.N  2008-07-24 20:37:36 
Re: Attaching events to dynamically created elements
Gregor Kofler <usenet@  2008-07-24 21:07:25 
Re: Attaching events to dynamically created elements
"C. (http://symcbean  2008-07-24 15:10:59 
Re: Attaching events to dynamically created elements
shuchow@[EMAIL PROTECTED]  2008-07-25 10:55:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 14:59:56 CDT 2008.