JQuery change inner text but preserve html
Solution 1:
This seems to work just fine.
Live Demo
<html>
<head>
</head>
<body>
<a href="link.html">Some text <img src="img.jpg" /></a>
</body>
</html>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var $link = $('a');
var $img = $link.find('img');
$link.html('New Text');
$link.append($img);
});
</script>
Solution 2:
Since you can't modify the link an option would be to simply use replace
$("a").html($("a").html().replace("Some text", "Other text"));
Example on jsfiddle.
Solution 3:
Wrap the text you want to change in a span
<a href="link.html"><span>Some text</span> <img src="image.jpg" /></a>
$('a span').html( 'new text' );