×

Html & Html5

it training classes Logo

The World's best Software Development Study Portal

Js getElementById



getElementById is unique within an HTML document. If the HTML document has multiple elements with the same id, the document. getElementById() method returns the first element it encounters.

Javascript getElementById method example

<html>

<body>

<script>

       function getcube(){

var number=document.getElementById("number").value;

alert(number*number*number);

  }

</script>

<form>

Number:<input type="text" id="number" name="number" />

<button type="button" value="cube" onclick="getcube()">submit</button>

</form>

</body>

</html>

Output

Number:








JS training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute