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)