I have a date inside a div tag and I want to split the text and wrap the second half of the text in a span tag with a class id on it.
<开发者_如何转开发;div class="date"> Wednesday, August 17</div>
I need everything after the comma to be wrapped in a span tag with a class like this.
<span class="highlight">August 17</span>
In its entire html it would look like this.
<div class="date"> Wednesday, <span class="highlight">August 17</span></div>
How would I go about this.
Something like (my prototype fu is weak but this works):
var div = $$('div.date')[0];
var parts = div.innerText.split(', ');
var html = parts[0] + ', <span class="highlight">' + parts[1] + '</span>';
div.innerHTML = html;
Here's demo: http://jsfiddle.net/mrchief/3Rc8U/3/
精彩评论