JSFiddle : http://jsfiddle.net/veksen/7TRgE/1/
If I call the variable value from inside my function, it works. However, it doesn’t if I call it outside of the function.
I feel like it has something to do with change, as it is first assigned ok, but won’t change.
var diff_res = { norm:0, nm:-40, hell:-100 };
var difficulty = "hell";
$("select").change(function () {
difficulty = $("select option:selected").val();
$(".inside").text(diff_res[difficulty]);
})
.change();
var char_fr = 30;
char_fr += diff_res[difficulty];
$(".outside").text(diff_res[difficulty]);
UPDATE:
By re-executing, I meant something like this:
The point was that
$(".outside").text(diff_res[difficulty]);is only being executed once, when the DOM is loaded, which is why thetext()is initially set to-100. To change the.outsideagain, you need to re-run$(".outside").text(diff_res[difficulty]);ORIGINAL:
Your problem is that:
is only executed one time, in the
$(document).ready()function. If you want it to change more often, you’ll need to re-execute that in yourchangehandler.