I have a database outputting either:
example-phrase
example2-phrase
orexample-solution
And I need to replace these on the page load with:
- Example Phrase
- Example 2 Phrase
- Example & Solution
I already have jQuery loaded on the page so I can use a jQuery solution, but I know it is also possible with some basic Javascript...the problem is I do not know any of either and the examples I'm finding are not doing what I need. I also need to be able to add more replacements in the future.
UPDATE: I have this from another project, but it replaces everything before (and including ) the "=" in any h2 elements on the page. That first line: var re = /^[^=]+=\s*/,
losses me with all the symbols, though:
<script>
var re = /^[^=]+=\s*/,
elements = document.getElementsByTagName('h2')
function processText(el) {
el.textContent = el.textContent.replace(re, '');
}
for(var i = 0, l = elements.length; i < l; i++) {
processText(elements[i]);
}
</script>