The answer to your IT questions
 

Advanced search  • Search tips
My QUESTIONS & ANSWERS
 Question:

Why this doesn't work in IE?

User ANONYMOUS
Published on: 19:36/23.07.2008
Status: 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;
}
 Answers: 1
Sort by: /\ date | rating
Image Answer by: xpert
Posted on: 19:36/23.07.2008
Rating: No votes so far
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
  
| Home | Hall of fame | Register | Log in | Terms of service | Help | Contacts |