Jump to content

translate jquery code to javascript


shahriar

Recommended Posts

<div class="price">4.21</div>
<div class="price">3.82</div>
<script>
var sum = 1;
$('.price').each(function()
{
    sum *= parseFloat($(this).text());
});
 document.write(sum);
</script>

Can anyone convert this into Java? read "price class" as anywhere in the template and multiply elements inside them.

Link to comment
Share on other sites

As soon as you execute the "document.write()" statement, the program reloads the page and you lose all earlier calculations and references.

Consider writing the results to another element and use ID values to help with references.

 

BTW, welcome to the forums. :)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...