Get price value from span tag and append it inside a div after multiplying with a number in JavaScript?

Extract the value and convert it from String to integer to get price value from span tag.


Following is the code −

<!DOCTYPE html>
<html lang="en">
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
<script src=""></script>
<script src=""></script>
      <td><strong><span class="purchase amount">
      <p id="demo"></p>
   $(document).ready(function () {
      var v = parseInt($(".purchase.amount")
      .replace(',', ''));
      var totalValue = v * 10;
      $("#demo").text("After multiplying the Value 10=" + totalValue);

To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.

This will produce the following output −

Following is the output on console −

This will produce the following output −

This will produce the following output on console −

Updated on: 24-Oct-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started