JavaScript static Method

Static methods in JavaScript is a way for providing class level methods. To declare a static method, we have to use static keyword as prefix with method name. Syntax: class className(){ static methodName(){ //method body } } Ways to call static methods 1. Using Class name ClassName.methodName(); 2. On the constructor property of the class … Read more

JavaScript Constructor Method

To initialize and create an object in Javascript, a constructor method is used which is called when memory is allocated for an object. A class in Javascript can contain one constructor method only, however, a parent class constructor can be used by using the super keyword. Example: <!DOCTYPE html> <html> <body> <script> class Student { … Read more

JavaScript Class

According to Wikipedia: In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods). A class in Javascript is a special type of function that contains various class members including methods or constructors. A class in JavaScript can be … Read more

JavaScript email validation

JavaScript email validation: An email is tricky because of its format. Some of the basic checks are as follows: Presence of @ and . character Presence of at least one character before and after the @. Presence of at least two characters after. (dot). Example <!DOCTYPE html> <html lang=”en”> <head> <script> function validateEmail(emailId) { var … Read more

JavaScript innerHTML property

The JavaScript innerHTML property is used to generate the dynamic HTML and is the easiest way to modify the content of an HTML element. The dynamic HTML can be a registration form, comment form, links, etc. Syntax 1: To change the content of an HTML element document.getElementById(id).innerHTML = new HTML Syntax 2: To get the … Read more

javascript getElementsByTagName

getElementsByTagName The document.getElementsByTagName(name) is a method of the document object that is used to get an element by its tag name. Syntax: document.getElementsByTagName(name) Example: <!DOCTYPE html> <html> <body> <h1>”Get Element by Tag Name!”</h1> <p>Example</p> <p id=”DOM”></p> <script> var x = document.getElementsByTagName(“h1”); document.getElementById(“DOM”).innerHTML = ‘The text in h1 is: ‘ + x[0].innerHTML; </script> </body> </html>