I need this javascript to run when the page is loaded:
document.body.innerHTML = document.body.innerHTML.replace(/\} \}/g, '}}');
I also need this jQuery to run when the page is loaded (handles my sidebar):
$('[data-toggle=offcanvas]').click(function() {
$('.row-offcanvas').toggleClass('active');
});
This works for the sidebar (placed just before </body>
):
<script>$(document).ready(function() {
$('[data-toggle=offcanvas]').click(function() {
$('.row-offcanvas').toggleClass('active');
});
});</script>
But if I add the regex line like this:
<script>$(document).ready(function() {
$('[data-toggle=offcanvas]').click(function() {
$('.row-offcanvas').toggleClass('active');
});
document.body.innerHTML = document.body.innerHTML.replace(/\} \}/g, '}}');
});</script>
The regex works but the sidebar bit stops working. Is this because I'm mixing Javascript and jQuery? How would I fix this? Thanks.
document.body.innerHTML = ...
replaces everything in the body, removing event handlers and pretty much everything else – adeneo 46 mins ago