<!DOCTYPE html> <html> <body> <form> Buttons: <input type="button" id="firstbtn" value="OK"> <input type="button" id="secondbtn" value="OK"> </form> <p>Click the button below to disable the first button above.</p> <button onclick="disableElement()">Disable button</button> <script> function disableElement() { document.getElementById("firstbtn").disabled=true; } </script> </body> </html>
<!DOCTYPE html> <html> <body> <button id="button1" name="button1">Click Me!</button> <p>The name of the button is: <script> document.write(document.getElementById("button1").name); </script></p> </body> </html>
<!DOCTYPE html> <html> <head> <script> function alertType() { alert(document.getElementById("myButton").type) } </script> </head> <body> <button id="myButton" type="button" onclick="alertType()">Click Me!</button> </body> </html>
<!DOCTYPE html> <html> <body> <input type="button" id="button1" value="Click Me!"> <p>The text on the button is: <script> document.write(document.getElementById("button1").value); </script></p> </body> </html>
<!DOCTYPE html> <html> <body> <form id="form1"> <button id="button1" type="button">Click me!</button> </form> <p>The id of the form containing the button is: <script> document.write(document.getElementById("button1").form.id); </script></p> </body> </html>