Get Button Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Button

Introduction

The Input Button object represents an HTML <button> element.

You can access an <button> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button id="myBtn" onclick="myFunction()" value="get the text that on the button">test</button>

<p id="demo"></p>

<script>
function myFunction() {// w w w .ja  v a  2  s .co  m
    var x = document.getElementById("myBtn").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials