in Advanced 

Question preview

HomeQuestion preview:
Log in

Why this doesn't work in IE?

image
ANONYMOUS
17:45/22.07.2008
Web development
OPEN
Why this structure doesn't work in my script in MSIE Browsers?

for (var b=0; b<100; b++)
{
   prop = 'example' + b;
   elem.innerHTML =  style.innerHTML + prop;
}
Do you know someone who could answer? Ask him for help
Answers: 1
Sort by: date rating
image xpert
22:36/23.07.2008
1 from possible 5 with 1 votes
Lets suppose you have styling element which is div container. You iterate from 0 to 99 and you want to join text 'exampleX' with the styling info from styleElement.
Probably you are missing "+=" operator and you are using operator "=" which will result in getting only last example99. In order to join all the result into one you will need to "append" to the current elem.innerHTML and not to replace it with "=" operator.
Here is complete javascript sample:
<html>
<body>
<script>
function extendEl() {
    var elem = document.getElementById('extElement');
    var style = document.getElementById('styleElement');
	for (var b=0; b<100; b++){   
		prop = 'example' + b;   
		elem.innerHTML +=  style.innerHTML + prop;
	}
}
</script>
<div id="styleElement"> * </div>
<div id="extElement"><a href="#" onclick="extendEl()">press to extend</a></div>
</body>
</html>
Vote:
Please vote! Your opinion matters!
If you haven't found what you've looking for, post a question
Ask question
| Home | Hall of fame | Registration | Log in | Terms of service | Privacy policy | Help | Contacts | RSS |