I pass a variable title
to my html document and access it there like this:
<h2><%= title %></h2>
How can I access the same variable inside the <script>
tag?
I tried the following but it gives me an error:
<script>
console.log(title);
</script>
Uncaught ReferenceError: title is not defined
Is this because the variable is in a different scope?
EDIT: I wanted to keep things simple in this post but based on the answers I realize that I should have mentioned that I use an external file for my script:
<script src="/javascripts/script.js"></script>
In this script I use jQuery for some stuff and I need the variable title
there.