Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Javascript Articles
Page 8 of 534
How can I pass a parameter to a setTimeout() callback?
To pass a parameter to setTimeout() callback, use the following syntax −setTimeout(functionname, milliseconds, arg1, arg2, arg3...)The following are the parameters −function name − The function name for the function to be executed.milliseconds − The number of milliseconds.arg1, arg2, arg3 − These are the arguments passed to the function.ExampleYou can try to run the following code to pass a parameter to a setTimeout() callback Submit function timeFunction() { setTimeout(function(){ alert("After 5 seconds!"); }, 5000); } Click the above button and wait for 5 seconds.
Read MoreHow to add a number of months to a date using JavaScript?
To add a number of months to a date, first get the month using getMonth() method and add a number of months.ExampleYou can try to run the following code to add a number of months var d, e; d = new Date(); document.write(d); e = d.getMonth()+1; document.write("Incremented month = "+e);
Read MoreHow to call a parent window function from an iframe using JavaScript?
To call a parent window function, use “window.top”.ExampleYou can try to run the following code to call a parent window function from an iframe function display(){ alert("Hello World!"); } Click
Read MoreIs it required to have a return a value from a JavaScript function?
A JavaScript function can have an optional return statement i.e. it’s optional to return a value. This statement should be the last statement in a function.For example, you can pass two numbers in a function and then you can expect the function to return their multiplication to your calling program.ExampleTry the following example. It defines a function that takes two parameters and concatenates them before returning the resultant in the calling program. function concatenate(first, last){ var full; full = first + ...
Read MoreHow to write a JavaScript function to get the difference between two numbers?
Use Math.abs() inside a JavaScript function to get the difference between two numbers in JavaScript.ExampleYou can try to run the following code to get the difference of numbers var num1, num2; num1 = 50; num2 = 35; var difference = function (num1, num2){ return Math.abs(num1 - num2); } document.write("Difference = "+difference(num1,num2));
Read MoreHow to use JavaScript to hide a DIV when the user clicks outside of it?
To hide a div when the user clicks outside of it, try to run the following codeExample window.onload = function(){ var hideMe = document.getElementById('hideMe'); document.onclick = function(e){ if(e.target.id !== 'hideMe'){ hideMe.style.display = 'none'; } }; }; Click outside this div and hide it.
Read MoreHow to break a loop in JavaScript?
The break statement is used to break a loop and continue executing the code, which is after the loop.ExampleYou can try to run the following code to break a loop in JavaScript var text = ""; var i; for (i = 0; i < 5; i++) { if (i === 2) { break; } text += "Value: " + i + ""; } document.getElementById("test").innerHTML = text; OutputValue: 0 Value: 1
Read MoreWhat are label statements in JavaScript?
JavaScript label statements are used to prefix a label to an identifier. A label can be used with break and continue statement to control the flow more precisely. A label is simply an identifier followed by a colon (:) that is applied to a statement or a block of code. We will see two different examples to understand how to use labels with break and continue.ExampleYou can try to run the following code to use labels to control the flow, with break statement document.write("Entering the loop! "); ...
Read MoreWhat is onclick event in JavaScript?
The onClick event is the most frequently used event type, which occurs when a user clicks the left button of the mouse.ExampleYou can put your validation, warning etc., against this event type. Click the following button and see result
Read MoreWhat is the difference between break with a label and without a label in JavaScript?
Break without labelThe break statement is used to exit a loop early, breaking out of the enclosing curly braces. The break statement exits out of a loop. ExampleLet’s see an example of break statement in JavaScript without using label − var x = 1; document.write("Entering the loop "); while (x < 20) { if (x == 5){ break; // breaks out of ...
Read More