I have an id=”test” and would like to have it replaced by the variable:PitchesRemaining:
http://jsfiddle.net/xtian/G7Qdp/
HTML:
<div class="wrap wrap-widgets relative">
<div class="speedometer" id="test">6</div>
<span id="AveragePitches">55</span>
<span id="PitchesToday">15</span>
</div>
Jquery:
$(function(){
var AveragePitches = parseInt($("#AveragePitches").text());
var Buffer = AveragePitches * .2;
var PitchesMax = AveragePitches + Buffer;
var PitchesToday = parseInt($("#PitchesToday").text());
var PitchesRemaining = PitchesMax - PitchesToday;
$("#test").change(function() {
PitchesRemaining = $(this).val();
}).change();
});
You can just change the Id using jQuery’s
attrmethod:I’m not sure what you’re trying to do though. If you’re trying to use the ID to track a variable, then perhaps you should take a look at
.datainstead.EDIT:
After reading your comment in the question; to change the text of the div to the value of
PitchesRemaining, just usetext:Or
html: