Found 6710 Articles for Javascript

How to register events in JavaScript?

Shubham Vora
Updated on 06-Sep-2022 14:06:20

3K+ Views

The interaction between HTML and JavaScript is handled through events. When a user accomplishes some action on the page, an event occurs. In this tutorial, we will learn how to register events in JavaScript. Let’s move forward to discuss this further. Using Inline Event Handlers Added as HTML Tag Attributes Here, we shall learn how this standard event registration works. Adding events to the DOM attribute is a regular practice. But this is a worse approach. Extending and maintaining the code becomes difficult as HTML and JavaScript come together. Second, if the code loads late when the user interacts with ... Read More

How can I save HTML locally with JavaScript?

Shubham Vora
Updated on 14-Jul-2022 12:19:53

5K+ Views

This tutorial teaches us to save HTML locally with JavaScript.What is local storage?Local storage means storing content inside your web browser locally. It means it takes space on your computer to store the content rather than storing it on the server of the web application. It is one kind of web API that contains all browsers by default.Local storage generally stores the application data, user’s secession data, authentication token, and many other things. Before HTML5, developers used cookies to store the HTML content locally, but now every browser has local storage.Also, cookies only allow storage of a maximum of 4kb ... Read More

How to show a foreach loop using a flow chart in JavaScript?’

Srinivas Gorla
Updated on 30-Jul-2019 22:30:21

1K+ Views

The following shows foreach loop using flow chart:

How to use OR condition in a JavaScript IF statement?

Abhinanda Shri
Updated on 19-Sep-2019 08:07:16

5K+ Views

To use OR condition in JavaScript IF statement, use the || operator i.e Logical OR operator. If any of the two operands are non-zero, then the condition becomes true.Here’s how you can use the operator || in JavaScriptExampleLive Demo                    var a = true;          var b = false;          document.write("(a || b) => ");          result = (a || b);          document.write(result);          

What is for each...in a statement in JavaScript?

Nikitha N
Updated on 16-Jun-2020 06:56:09

159 Views

The for each...in loop iterates a variable overall value of the properties of objects. Note − The “for…each..in” is now deprecated. Do not use. SyntaxHere’s the syntax −for each (variablename in object) {    statement or block to execute }ExampleHere’s an example, which will not run on any of the web browsers, since “for each..in” is now deprecated −                    var myObj = {myProp1:30, myProp2: 40};          var sum = 0;          for each (var value in myObj) {             sum += value;          }          document.write(sum);          

How to edit a JavaScript alert box title?

Vrundesha Joshi
Updated on 08-Jan-2020 10:57:06

7K+ Views

It’s not possible to edit a JavaScript alert box title due to security issues. Still, to edit an alert box to work it all web browsers, use custom JavaScript Modal Dialogs or jQuery plugins.You can also use a custom alert box like Sweet Alert to get a custom alert box, with a title of your choice:

How to create a custom object in JavaScript?

vanithasree
Updated on 19-Sep-2019 08:11:53

497 Views

To create a custom object in JavaScript, try the following codeExampleLive Demo                          var dept = new Object();          dept.employee = "Amit";          dept.department = "Technical";          dept.technology ="Java";          document.getElementById("test").innerHTML =          dept.employee + " is working on " + dept.technology + " technology.";          

What is super() function in JavaScript?

radhakrishna
Updated on 08-Jan-2020 10:55:23

268 Views

Use the super() function to call the constructor of the parent class and access functions on an object's parent class.ExampleYou can try to run the following code to implement super()Live Demo                    class Department {             constructor() {}             static msg() {                return 'Hello';             }          }          class Employee extends Department {             constructor() {}             static displayMsg() {                return super.msg() + ' World!';             }          }          document.write(Employee.displayMsg());          

What is the difference between for...of and for...in statements in JavaScript?

Ankitha Reddy
Updated on 15-Jun-2020 12:16:31

261 Views

for…in loopThe “for...in” loop is used to loop through an object's properties.Here’s the syntax −Syntaxfor (variablename in object) { statement or block to execute }You can try to run the following example to implement ‘for-in’ loop. It prints the web browser’s Navigator objectExampleLive Demo var aProperty; document.write("Navigator Object Properties "); for (aProperty in navigator) { document.write(aProperty); document.write(""); } document.write ("Exiting from the loop!"); for…of loopThe “for…of” loop is used to loop through iterable objects, which includes Map, Array, arguments, etc.SyntaxHere’s the syntax −for (variablename of iterable){ statement or block to execute }ExampleHere’s an example showing ... Read More

How to call a JavaScript function on submit form?

mkotla
Updated on 30-Jul-2019 22:30:21

16K+ Views

The onsubmit event occurs when you try to submit a form. You can put your form validation against this event type. The following example shows how to use onsubmit. Here we are calling a validate() function before submitting a form data to the webserver. If validate() function returns true, the form will be submitted, otherwise it will not submit the data.     The HTML code snippet. …

Advertisements