Can you create a dynamic javascript function and immediately call it?
I already found that you can’t use the callback from append.
proposed, non working, code:
<script type="text/javascript">
var count=1;
$(document).ready(function(){
$(".main").append('
<script type="text/javascript">function init'+count+'(){alert("'+count+'");}<'+'/script>
');
window['init'+count]();
});
</script>
<div class="main"></div>
Edit:
Narrowed it down to a synchronization problem. Placing alert("") between append and window makes it work, but that is not really a useful fix because the count might go up to a 100 when I place this code in a loop.
Guess I’ll have to keep looking.
That should work, but you aren’t quoting correctly. There shouldn’t be any unescaped double quotes within
append("and"). Try: