Monday, 17 July 2023

getElementById in JavaScript_1

getElementById
  •  The getElementById() method returns an element with a specified value.
  • The getElementById() method returns null if the element does not exist.
  • The getElementById() method is one of the most common methods in the HTML DOM. It is used almost every time you want to read or edit an HTML element.
  • If two or more elements with the same id exist, getElementById() returns the first.
Example:
<!DOCTYPE html>
<html>
<head>
<title>getElementById</title>
<script type="text/javascript">  
function getcube()
{  
var number=document.getElementById("number").value;  
alert("Cube= "+number*number*number);  
}  
</script> 
</head> 
<form>  
Enter No:<input type="text" id="number" name="number"/><br/>  
<input type="button" value="cube" onClick="getcube()"/>  
</form>  
<body>
</body>
</html>

0 comments

Post a Comment