Am now facing an other challenge. Some parts of my html code has the following lines:
<div class="action-body flooded"><p>(In <span class="error">[82681]</span>) refs <a href="/browse/AGLBD-16096" title="GlobalTestSuite tracking">AGLBD-16096</a><br/></div> I have to get the number with-in the [] and then replace it with a hyperlink. I have tried using document.getElementsByClassName('error') but its not working. how can I make it work? and i would also need to iterate in a loop to replace all such numbers if there are more than one in []. e.g: [123] [234] [345]...
This is all what I have written till now with pimvdb's help:
<script type="text/javascript"> var bodyText = document.getElementById('body').innerHTML; var pattern = /\[.*?\]/g; var replaceText = "<a href=\"www.mysite.com\">Pradeep</a>"; document.getElementById('body').innerHTML = bodyText.replace(pattern, replaceText); </script>
document.bodygives you the body element. What you're using looks for an element with the id body. Otherwise, this appears to work.