This is a simplified version of my problem. I have two passages, and the second is rendered within the first.
:: one
<div class="test">
This is passage one
</div>
<%= story.render( "two" ) %>
:: two
<script>
$('.test').addClass('red')
</script>
<div class="test">
This is passage two.
</div>
Add to this a CSS declaration .red {color:red}
.
My intended result is:
<div class="red test">
This is passage one.
</div>
<div class="test">
This is passage two.
</div>
But the actual result is:
<div class="red test">
This is passage one.
</div>
<div class="red test">
This is passage two.
</div>
See what Iām trying to do? Iām expecting the script tag to be run in the place where itās written, before the second ā.testā div is added to the DOM, so it can only select the first ā.testā. However, the script runs some time later, selecting both ā.testā divs.
Is there anything Iām doing wrong? I need a systematic solution for this: Iām not doing this by hand in a few passages, itās the way that the whole game works: rendering a passage within the current passage, then changing the previous text. (Itās of course a lot more complex than this example.)
Thanks!