
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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.
Example
Following is the code −
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <body> <tr> <th>Value=</th> <td><strong><span class="purchase amount"> <span></span>10</span></strong> </td> <p id="demo"></p> </tr> </body> <script> $(document).ready(function () { var v = parseInt($(".purchase.amount") .text() .trim() .replace(',', '')); var totalValue = v * 10; console.log(totalValue); $("#demo").text("After multiplying the Value 10=" + totalValue); }); </script> </html>
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 −
- Related Articles
- Get value from div with JavaScript resulting undefined?
- How to get id from tr tag and display it in a new td with JavaScript?
- Format MySQL records (price values) after multiplying them
- Is wrapping a div inside an anchor tag valid code?
- Replace() with Split() in JavaScript to append 0 if number after comma is a single digit
- How to get innerHTML of a div tag using jQuery?
- JavaScript - Get the text of a span element
- How to append HTML code to a div using JavaScript?
- Remove any text not inside element tag on a web page with JavaScript?
- Get div height with vanilla JavaScript
- How to combine multiple elements and append the result into a div using JavaScript?
- Get field value and convert a particular character from it to uppercase with MySQL
- How to clear all div’s content inside a parent div in JavaScript?
- Get number from user input and display in console with JavaScript
- How to get a number value of a string in Javascript?

Advertisements