Yes, you must escape any contained delimiters as rangana says, it doesn't hurt to escape closing slashes (/) too, as not doing so can confuse the browser, and will make your code invalid (usually there is no problem, so people often skip this). Also you should return false. If you are using this in several places, the easiest way is to return the function (get rid of the language attribute - it's deprecated):
Code:
<script type="text/javascript">
function ChangeTxt(txt) {
document.getElementById('ref').innerHTML = txt;
return false;
}
</script>
The when you use it (closing slashes escaped, return added):
Code:
<td><a href="#nogo" onclick="return ChangeTxt('oneoneoneone<b>one<\/b>oneone')">one</a></td>
<td><a href="#nogo" onclick="return ChangeTxt('two<span style=\'color:red\'>twotwotwo<\/span>twotwotwo')">two</a></td>
<td><a href="#nogo" onclick="return ChangeTxt('threethreethreethreethree')">three</a></td>
The return is very important because many browsers will still execute the link if the onclick event doesn't return false. Even though your link is to a named anchor, this will still reload the page in many browsers, wiping out any changes that the event made to the document.
Bookmarks