Trying to clear my HTML code, is it correct if in my web page I declare many blocks of <script>
.
Like this:
<script type="text/javascript">
...
...
</script>
<script type="text/javascript">
...
...
</script>
<script type="text/javascript">
...
...
</script>
I mean, I do this in order to group jquery functions and allow to declare variables inside each <script>
block that will not affect other <script>
blocks.
Your script
blocks are not likely having the effect you are expecting, since javascript scope rules do not work that way. Scripts in one block can absolutely affect scripts in another block, if the variables and functions are not scoped properly. Javascript variables and functions are globally scoped unless you follow specific procedures to encapsulate them, and script
blocks do not accomplish this.
You should read up on scope in javascript, perhaps a good article or two, and consider why it’s best to not embed your javascript functionality in script
blocks, but instead place them in well-defined files following common javascript patterns such as the javascript module pattern.
1