I want to dynamically print values and strings on my Twig template using JavaScript code. But it doesn't work.
Also when I load the Twig template, it should show the contents of the "test" on page, which is just "asdasd".
But it doesn't work. What I get is nothing, as if no script code exists.
Here's the code I have on my Twig template:
<div id="output">
</div>
<script type="text/javascript">
var $queryString;
$queryString = queryString.replace(new RegExp("pageno" + "=\\w+"),"").replace("?&","?").replace("&&","&");
var test;
test = "asdasd";
document.getElementById('output').innerHTML = test;
alert("HHHHhhhhhhHHHALSDJLKJ");
</script>
I don't get any alert either.
I did follow: https://www.guru99.com/introduction-to-javascript.html
I just did read in this link: Why does jQuery or a DOM method such as getElementById not find the element?
that we have to add before the script. I did that too, but still it doesn't work.
Why the varible won't show when I load the page ?