Okay I'm probably being thick, but I can't get something to work and its bugging me why. I'm using the global replace property in Javascript, but whenever I do it wont work outisde the DIV I'm in.
The DIV I'm in isnt the one I need to target, but a simplified example is below.
<div id="foo">
<a href="http://www.somesite.com" target="_blank" class="footer">Site 1</a>
</div>
<script type="text/javascript">
window.onload = function replaceScript() {
var replacement = '<a href="http://www.somesite.com" target="_blank" class="footer">Site 1</a>';
var text = '<a href="http://www.othersite.com" title="Other Site" target="_blank">Site 2</a>';
document.getElementById("foo").innerHTML = text.replace(new RegExp(replacement, 'g'), '');
}
</script>
The other way I was trying it was this:
<script type="text/javascript">
window.onload = function replaceScript() {
var toReplace = '<a href="http://www.somesite.com" target="_blank" class="footer">Site 1</a>';
var replaceWith ='<a href="http://www.othersite.com" title="Other Site" target="_blank">Site 2</a>';
document.getElementById("foo") = document.body.innerHTML.replace(toReplace, replaceWith);
}
</script>
But I can't get that one to work globally,