For performance and organizational reasons, I like to keep the markup in the HTML (instead of building big HTML strings in javascript), so I usually create hidden template nodes for this sort of thing. The jQuery function you want is replaceWith().
HTML:
<span class="error">ORIGINAL TEXT</span>
<span class="error">ORIGINAL TEXT2</span>
<div class="ui-widget" id="error-template" style="display:none;">
<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"> </span>
<strong>ORIGINAL TEXT</strong></p>
</div>
</div>
SCRIPT:
$(document).ready(function() {
$('span.error').each(function(i,v) {
var text = $(this).text();
var newBlock = $('#error-template').clone().removeAttr('id').show();
newBlock.find('strong:first').text(text);
$(this).replaceWith(newBlock);
});
});
sunetos
2010-07-14 18:53:07