Answers for "how to add <a> in javascript"

11

how to add elements in javascript html

//adding 'p' tag to body

  var tag = document.createElement("p"); // <p></p>
  var text = document.createTextNode("TEST TEXT"); 
  tag.appendChild(text); // <p>TEST TEXT</p>
  var element = document.getElementsByTagName("body")[0];
  element.appendChild(tag); // <body> <p>TEST TEXT</p> </body>
Posted by: Guest on May-31-2020
4

javascript function to add two numbers

<!--Add two integer numbers using JavaScript.-->
<html>
	<head>
		<title>Add two integer numbers using JavaScript.</title>
		<script type="text/javascript">
			function addTwoNumbers(textBox1, textBox2){
				var x=document.getElementById(textBox1).value;
				var y=document.getElementById(textBox2).value;
				var sum=0;
				sum=Number(x)+Number(y);
				alert("SUM is: " + sum);
			}
		</script>
	</head>
<body>
	<h1>Add two integer numbers using JavaScript.</h1>
	<b>Enter first Number: </b><br>
	<input type="text" id="textIn1"/><br>
	<b>Enter second Number: </b><br>
	<input type="text" id="textIn2"/><br><br>
	<input type="button" id="btnSum" value="Calculate SUM" onClick="addTwoNumbers('textIn1','textIn2')"/>
</body>

</html>
Posted by: Guest on April-11-2020

Code answers related to "how to add <a> in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language