“demo” is not an id that exists in your example. Also, I’m fairly certain you are trying to use php as javascript in there.
<a id='demo' href="">is you good</a>
<script>
const spaceToPlus = (content) => {
return content.replace(/ /g, '+');
}
let anchor = document.getElementById('demo')
let attributeHref = spaceToPlus(anchor.innerHTML);
anchor.setAttribute('href', attributeHref);
</script>
0
solved How To replace Space by ‘+’ sign using javascript