Is there a way to achieve functionality similar to Ruby's gsub in JavaScript? I am working with a local HTML file and need to replace specific template variables with content, but I am struggling to find a solution. The HTML code includes elements like the following:
<div id="content">
<h1>{{title}}</h1>
{{content}}
</div>
If I enclose each template variable in a named div tag, I could potentially use jQuery's replaceAll method for substitution. However, I am looking for a way to perform this task without having to wrap each variable in a div.
I simply wish to execute something like $('document').gsub("{{title}}", "I am a title").
Do you have any suggestions or ideas on how to accomplish this?
Thank you for your assistance!