Javascript examples for Statement:if
Check if an element is available with if statement
<html> <head></head> <body> <button onclick="myFunction()">Click me</button> <!-- <input type="text" id="demo"></input> --> <script> function myFunction() {//from w w w .j av a 2 s.co m var message = undefined; if (document.getElementById("demo")) message = document.getElementById("demo").value; if ( message ) console.log(message); else console.log("undefined"); } </script> </body> </html>