I have some jQuery global variables that I want to just put into my HTML document so that as they’re updated via some update function, they’ll just update in each spot that the global is referenced automatically. This would save me from writing a function that updates the text.
Basically I want to do this:
<html>
<head>
<script>
var globalVariable= "something";
</script>
</head>
<body>
<p>The jQuery global variable is equal to: $(globalVariable)</p>
<body>
</html>
Would this even work? Would they update in the page when they are updated in the jQuery?
You can’t do this in jQuery, for this functionality it’s better to use an MVC or MVVM framework, I would recommend knockout.js (http://knockoutjs.com/), it’s very easy to bind variables to DOM elements with it: