Oh, another method is to store the default values as a Javascript array/object with a matching ID of the DIV. For example:
var defaults = { 'div1': 100, 'div2': 200 } <div id="div1" class="num">100</div> <div id="div2" class="num">200</div> alert( defaults['div1'] ); // alerts '100' On Oct 14, 8:29 am, Avik Basu <avikb...@gmail.com> wrote: > Thanks for your help--using .text() solved the scaling problem. A > related problem is how can I go back to the original values in the > divs when scaling multiple times? Right now the behavior is such that > it scales the div values properly the first time, but the second time > it scales the already scaled values. What is a good way to always > scale from the original div values? > > On Oct 13, 6:14 pm, "mike.helgeson" <mike.helge...@gmail.com> wrote: > > > parseFloat( $( this ).text() ) // divs don't have a value > > > On Oct 13, 4:07 pm, Avik Basu <avikb...@gmail.com> wrote: > > > > I would like to use JQuery to iterate through a set of <div> elements > > > that have the same class and scale each value according to a value > > > selected from a dropdown box. For example, > > > > <select id="factor"> > > > <option value="1">1</option> > > > <option value="2">2</option> > > > <option value="3">3</option> > > > </select> > > > > <div class="num">100</div> > > > <div class="num">1000</div> > > > <div class="num">10000</div> > > > > If "2" was the scaling factor chosen, then the divs would look like: > > > > <div class="num">200</div> > > > <div class="num">2000</div> > > > <div class="num">20000</div> > > > > This is the jQuery script that attempts to do the iteration and > > > scaling, but I keep get NaNs. I suspect it has something to do with > > > my use of the .each iterator or the $(this) notation, but have not > > > been able to solve it. > > > > <script> > > > $("#factor").change(function(){ > > > $(".num").each(function(){ > > > $(this).html(parseFloat($(this).val()) * parseFloat(jQuery > > > ("#factor").val())); > > > });}); > > > > </script> > >