Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • JAVASCRIPT OUTPUT DISPLAY FUNCTIONS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 237
    Comment on it

    In javascript we use different functions to display outputs, like to display into an alert box, HTML output, HTML element,browser console we use different functions.

    1. window.alert():- Used when we want to display data into an alert box.

    Example:-

     <!DOCTYPE html>
    <html>
    <body>
    
    <h1>Output in an Alert box</h1>
    
    <script>
    window.alert(3*2+5);
    </script>
    
    </body>
    </html>
    

    2. document.write():- Used when we want to display data into the HTML output.

    Example:-

    <html>
       <head>
    
          <script type="text/javascript">
             function sayHello()
             {
                document.write ("Hello there!");
             }
          </script>
    
       </head>
       <body>
          <p>Click the following button to call the function</p>
    
          <form>
             <input type="button" onclick="sayHello()" value="Say Hello">
          </form>
    
          <p>Use different text in write method and then try...</p>
       </body>
    </html>
    

    3. innerHTML:- Used when we want to display data into a HTML element.

    Example:-

     <!DOCTYPE html>
    <html>
    <body>
    <p>Inner HTML</p>
    
    <p id="show"></p>
    
    <script>
    document.getElementById("show").innerHTML = 3*2+5;
    </script>
    
    </body>
    </html> 
    

    4. console.log():-Used when we want to display data into the browser element.

    Example:-

    <!DOCTYPE html>
        <html>
        <body>
    
        <h1>Output in an Alert box</h1>
    
        <script>
       console.log(3*2+5);
        </script>
    
        </body>
        </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: