Replacing strings with javascript
I'm @little te@pot
Output goes here
<p id="source">I'm @little te@pot</p>
<p id="output">Output goes here</p>
<p><a href="#" onClick="return replaceText()">Replace Text</a></p>
<script type="text/javascript">
function replaceText(){
sourcetext = document.getElementById('source').innerHTML;
// The string replace function
outputtext = sourcetext.replace(/@/gi, "REPLACEMENT");
document.getElementById('output').innerHTML = outputtext;
return false;
}
</script>
© 2024 Invent Partners Ltd | Supporters of FdA Web Design, Wakefield