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!