I'm trying to perform a calculation and display it dynamically on html.
How can I format text output only in a selected area.
The calculate(), generate assign the value for the var power.
How can i display result in following format in html. If possible the correct method in Jquery and pure js version.
rated power: 18 watts.
function calculation() {
var num1 = document.getElementById("num1");
var num2 = document.getElementById("num2");
var power = (parseFloat(num1.value) * parseFloat(num2.value));
console.log("Power = " + power + " watts");
/* html output */
$("#resultpad").text("Rated Power :" + power + " watts");
// Is it possible only to display the value of Variable power in bold text <strong>power</strong> watts
}
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<body>
<div id="inputForm">
<p>Fill electrical ratings</p>
<p>Voltage:
<input type="text" name="num1" id="num1" />
</p>
<p>Current:
<input type="text" name="num2" id="num2" />
</p>
<p id="resultpad"></p>
<!-- outout generated by calculation() -->
<p>
<button onclick="calculation()">Submit</button>
</p>
</div>
</body>
<span>tag.<p>Rated Power : <span id="resultpad"></span> watts</p>.