Reputation: 3610
In the following example from jquery UI, we have an alert box:
<div class="ui-widget">
<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>
Alert: something went wrong</p>
</div>
</div>
I want to be able to edit the alert text without deleting the section which takes care of the alert icon... but also without writing all the widget html inside javascript.
If I do something like $('p').html("new alert")
, it removes the span (icon) part. Same happens if I use $('p').text("new alert")
.
Any idea how I can do this?
Upvotes: 1
Views: 537
Reputation: 3080
You could rather change your html structure, but in case you don't want to, try this:
var $p = $('p');
$p.find('span').appendTo($p.html('Not an alert anymore'));
Upvotes: 0
Reputation: 9612
Try this out http://jsfiddle.net/euFUL/
HTML
<div class="ui-widget">
<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>
<span id="ErrorMsg">Alert: something went wrong</span>
</p>
</div>
</div>
JS
$(function () {
$('#ErrorMsg').text("new alert");
});
Upvotes: 1
Reputation: 10294
You could use an inner div element and put text on that
<div><span></span><div id="innerDiv"></div></div>
Upvotes: 1