• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic Element Function Parameter

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a DIV like so:

var div = document.createElement("DIV");

and adding an onmousedown function like so

div.onmousedown = someFunction;

What I need to do though is pass an argument to someFunction. If I create it statically, it would take 2 arguments (event, id). I know that the above code passes event automatically, but how can I also pass it a string value for id?

Thanks.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something like?:

= function(){someFunction(event,"id");}

Eric
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I tried that before, and it says that event is not defined. What I am trying to duplicate dynamically is the following static html:

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this:



[ugh smiles!]
[ugh mistake - should work now in FF]
[ March 28, 2006: Message edited by: Eric Pascarello ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get event is not defined, in FF.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, well, while I await anyone's suggestions for the above solution, I have figured out a workaround. I created the DIV in HTML and set the display to none. When I need a new one, I use the cloneNode function of that div, give it a new ID and various other properties and all works well.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should have worked if I would have not typed it wrong....


Eric
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect Eric. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic