rf9
06-16-2008, 10:55 AM
Hello, first post here and also fairly new to javascript so please excuse any lameness. I'm using my Actionscript knowledge as the basis for my javascript, they seem pretty similar.
I'm trying to select a div that has been generated by javascript. I'm not sure where I'm going wrong. I have 5 divs named title0, title1 and so on and I want to target one using the variable i.
The last line does not work, it returns null or no properties, maybe my syntax is wrong. I kinda made it up :)
var i = 0;
var setProperties = function() {
alert(i); // this works
var userInput = document.getElementById('element_label').value;
document.getElementById('title' + [i]).innerHTML = userInput;
}
If I change the last line to this then the targetting works:
document.getElementById('title' + 1).innerHTML = userInput;
Any advice much appreciated.
I'm trying to select a div that has been generated by javascript. I'm not sure where I'm going wrong. I have 5 divs named title0, title1 and so on and I want to target one using the variable i.
The last line does not work, it returns null or no properties, maybe my syntax is wrong. I kinda made it up :)
var i = 0;
var setProperties = function() {
alert(i); // this works
var userInput = document.getElementById('element_label').value;
document.getElementById('title' + [i]).innerHTML = userInput;
}
If I change the last line to this then the targetting works:
document.getElementById('title' + 1).innerHTML = userInput;
Any advice much appreciated.