You can store the original inside the <div> element as an attribute.
There are several ways you can do this. Here are the popular methods:

One method is using the jQuery data() function:
http://docs.jquery.com/Core/data
However, this would require you to add the data via Javascript, which
maybe not what you want because of the extra overhead processing.

Another method is using directly coding the attribute in the HTML, and
use the metadata plugin:
http://plugins.jquery.com/project/metadata

Then use the original data in the calculations instead of what's
inside the div.text().

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>
>
>

Reply via email to