I am customising a chat based web interface. I have very limited control over the markup being used.
Basically, I want to add new element <span class="icon" />
to each chat message.
<div id="chatLog">
<span class="msg agent">
<strong>Agent Name</strong>
Hi, how are you today? How can I help?
</span>
<span class="msg customer">
<strong>Customer Name</strong>
I'm fine thanks, please can you tell me more about the products you sell?
</span>
</div>
The jquery I would like to use is something like this:
<script>
jquery('.msg').append('<span class="icon" />');
</script>
So I have
<div id="chatLog">
<span class="msg agent">
<strong>Agent Name</strong>
Hi, how are you today? How can I help?
<span class="icon" />
</span>
<span class="msg customer">
<strong>Customer Name</strong>
I'm fine thanks, please can you tell me more about the products you sell?
<span class="icon" />
</span>
<div id="chatLog">
The markup will be continually changing as more and more messages are sent between the agent and the customer. How can I ensure all chat messages span.msg
have this new element <span class="icon" />
appended?
<div id="chatLog">
<span class="msg agent"><strong>Agent Name</strong>Hi, how are you today? How can I help?</span>
<span class="msg customer"><strong>Customer Name</strong>I'm fine thanks, please can you tell me more about the products you sell?</span>
<span class="msg agent"><strong>Agent Name</strong>Yes certainly, any particular product?</span>
<span class="msg customer"><strong>Customer Name</strong>Product ISBN-123-456 please</span>
<div id="chatLog">
` to be, in the message? And, incidentally, a `p` should *not* be nested within a `span` (that's invalid HTML, I'm afraid).
– David Thomas Jun 19 '13 at 14:12