![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi I'm trying to do something like this. for(i=0; i<5; i++){ var theData = document.createElement('a'); theData.onmouseover = function() { return get(i);} ... ... } But it won't work, because all the get(i) is get(4)... I know why this happens, but I don't know how to solve it... anybody have an idea? |
#3
| |||
| |||
|
|
for(i=0; i<5; i++){ var theData = document.createElement('a'); theData.onmouseover = function() { return get(i);} ... } Elementary my dear Kim. var theData = document.createElement('a'); // take this non changing line outside the for-loop for(i=0; i<5; i++){ theData.onmouseover = function() { return get(i);} } Evertjan. |
#4
| |||
| |||
|
|
I'm pretty sure the OP wants to generate 5 links. Your suggestion only generates 1 link and then assigns 5 functions to it, each overwriting the last. Would this work?: for(i=0; i<5; i++){ var theData = document.createElement('a'); theData.onmouseover = new Function("return " + i + ";"); ... } |
#5
| |||
| |||
|
|
Hi I'm trying to do something like this. for(i=0; i<5; i++){ var theData = document.createElement('a'); theData.onmouseover = function() { return get(i);} ... ... } But it won't work, because all the get(i) is get(4)... I know why this happens, but I don't know how to solve it... |
#6
| |||
| |||
|
|
Jambalaya wrote on 28 sep 2005 in comp.lang.javascript: I'm pretty sure the OP wants to generate 5 links. Your suggestion only generates 1 link and then assigns 5 functions to it, each overwriting the last. Would this work?: for(i=0; i<5; i++){ var theData = document.createElement('a'); theData.onmouseover = new Function("return " + i + ";"); ... } Well yes, but returning a value to a <a> mouseover is not doing anything. Try this [ie6 tested]: ========== body script type='text/javascript' for(i=0; i<5; i++){ myLink = document.createElement("a"); myLink.href = "http://www.cnn.com/"; myLink.innerHTML='CNN: '+i+'<br>' myLink.onmouseover = new Function("alert('number: "+i+"');"); document.body.appendChild(myLink); } /script ========== -- Evertjan. The Netherlands. (Replace all crosses with dots in my emailaddress) |
#7
| |||
| |||
|
|
"Evertjan." <exjxw.hannivoort (AT) interxnl (DOT) net> skrev i en meddelelse news:Xns96DFE04B047B7eejj99 (AT) 194 (DOT) 109.133.242... Try this [ie6 tested]: ========== body script type='text/javascript' for(i=0; i<5; i++){ myLink = document.createElement("a"); myLink.href = "http://www.cnn.com/"; myLink.innerHTML='CNN: '+i+'<br>' myLink.onmouseover = new Function("alert('number: "+i+"');"); document.body.appendChild(myLink); } /script ========== |
|
Thanks that worked... ..for IE6, but not firefox so..next question... can it be done in firefox? |
#8
| |||
| |||
|
|
Thanks that worked... ..for IE6, but not firefox so..next question... can it be done in firefox? "Evertjan." <exjxw.hannivoort (AT) interxnl (DOT) net> skrev i en meddelelse news:Xns96DFE04B047B7eejj99 (AT) 194 (DOT) 109.133.242... Jambalaya wrote on 28 sep 2005 in comp.lang.javascript: I'm pretty sure the OP wants to generate 5 links. Your suggestion only generates 1 link and then assigns 5 functions to it, each overwriting the last. Would this work?: for(i=0; i<5; i++){ var theData = document.createElement('a'); theData.onmouseover = new Function("return " + i + ";"); ... } Well yes, but returning a value to a <a> mouseover is not doing anything. Try this [ie6 tested]: ========== body script type='text/javascript' for(i=0; i<5; i++){ myLink = document.createElement("a"); myLink.href = "http://www.cnn.com/"; myLink.innerHTML='CNN: '+i+'<br>' myLink.onmouseover = new Function("alert('number: "+i+"');"); document.body.appendChild(myLink); } /script |
#9
| |||
| |||
|
|
Hi I'm trying to do something like this. for(i=0; i<5; i++){ var theData = document.createElement('a'); theData.onmouseover = function() { return get(i);} ... ... } But it won't work, because all the get(i) is get(4)... I know why this happens, but I don't know how to solve it... |
![]() |
| Thread Tools | |
| Display Modes | |
| |