I would like to change the text of a HTML element but preserve the rest of the inner html with jQuery.
For instance:
Some
An efficient and robust way that doesn't require you to know what the inner elements are or what the text is:
var $a = $('a'); var inner = ''; $a.children.html().each(function() { inner = inner + this.outerHTML; }); $a.html('New text' + inner);