Lokesh Yadav

Lokesh Yadav

38 Articles Published

Articles by Lokesh Yadav

38 articles

How to Find the action Attribute and method of a Form in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 3K+ Views

In HTML forms, the action and method attributes control where form data is sent and how it's transmitted. JavaScript provides properties to access and modify these attributes dynamically. The action attribute specifies the URL where form data should be sent when submitted, while the method attribute determines the HTTP method used for submission (GET, POST, or dialog). Using the action Property The action property allows you to get or set the form's action attribute value. Syntax // Get action attribute let actionValue = document.getElementById('formID').action; // Set action attribute document.getElementById('formID').action = 'newURL'; ...

Read More

Sibling of a list element in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 6K+ Views

In JavaScript, you can find sibling elements using DOM traversal properties. Siblings are elements that share the same parent element and exist at the same level in the HTML structure. Available Properties JavaScript provides several properties to navigate between sibling elements: nextSibling - Returns the next node (including text and comment nodes) nextElementSibling - Returns the next element sibling only previousSibling - Returns the previous node (including text and comment nodes) previousElementSibling - Returns the previous element sibling only Syntax node.nextSibling node.nextElementSibling node.previousSibling node.previousElementSibling Key Difference: nextSibling vs nextElementSibling ...

Read More

Another method other than a constructor in a JavaScript class?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 291 Views

JavaScript classes support multiple types of methods beyond constructors. While constructors initialize objects, other methods provide functionality and behavior to class instances. The constructor is used to create and initialize an instance of a class. However, classes can contain additional methods that perform specific operations, calculations, or return formatted data. These methods are called on class instances and have access to the object's properties through the this keyword. Types of Methods in JavaScript Classes JavaScript classes support several method types: Instance methods: Called on class instances Static methods: Called on the class itself Getter/Setter methods: ...

Read More

Super keyword in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 1K+ Views

In this article, we are going to discuss about the super keyword in JavaScript with suitable examples. The super keyword is used in JavaScript classes to access properties and methods of a parent class from a child class. It's essential for implementing proper inheritance in object-oriented programming. When a child class and parent class have methods with the same names, the super keyword helps distinguish between them. The child class must extend the parent class using the extends keyword to use super. Syntax The syntax to represent the super keyword is: super(arguments); ...

Read More

How to access an object value using variable key in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 14K+ Views

In this article we are going to discuss how to access an object value using variable key in JavaScript. An object value can be accessed by a Dot Notation and a Bracket Notation. To get the object value through a variable key, the value or expression inside the bracket notation must match with the existing key name, then it returns a value. The bracket notation, unlike the dot notation can be used with variables. If we are using a variable with bracket notation, the variable must reference a string. Let's understand this concept better with the help of ...

Read More

First and last child node of a specific node in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 877 Views

In JavaScript, you can access the first and last child nodes of any DOM element using built-in properties. There are four key properties: firstChild, lastChild, firstElementChild, and lastElementChild. Key Differences The main difference between these properties is how they handle whitespace and text nodes: firstChild and lastChild return any node, including text nodes (whitespace) and comments firstElementChild and lastElementChild return only HTML element nodes, ignoring whitespace and comments Syntax // First child properties element.firstChild // Returns any node (including text/whitespace) element.firstElementChild // Returns only element ...

Read More

How to add a method to a JavaScript object?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 7K+ Views

In this article, we'll go over how to add a method to a JavaScript object in JavaScript with appropriate examples. A JavaScript object is an entity which has properties. A property can be a variable or a method which define state and behavior of the object. A method is a property of an object that adds behavior to an object. We can add a method to a JavaScript object using object prototype. All JavaScript objects get their attributes and methods from a prototype. Let's understand this concept better with the help of examples further in this article. ...

Read More

How to set dynamic property keys to an object in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 3K+ Views

Setting dynamic property keys allows you to create object properties with names that are determined at runtime. JavaScript provides three main approaches to accomplish this. Method 1: Bracket Notation The simplest way is using bracket notation to assign a value to a dynamically named property: Dynamic Property Keys - Bracket Notation Setting Dynamic Property Keys using Bracket Notation let Employee = { ...

Read More

Add a property to a JavaScript object constructor?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 920 Views

In this article, we'll go over how to add properties to a JavaScript object constructor with appropriate examples. Adding a property to an object constructor is different from adding a property to a normal object. Properties must be added inside the constructor function itself, not outside. This ensures all instances created from the constructor have access to these properties. To get a better understanding, let's look at the syntax and usage of constructors in JavaScript. Syntax The syntax for a constructor is: function Constructor() { // No parameters } ...

Read More

Getters and setters in JavaScript classes?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 6K+ Views

In this article we are going to discuss about the getters and setters in JavaScript classes with suitable examples in JavaScript. In JavaScript, getters and setters are special methods that provide controlled access to object properties. They allow you to define custom behavior when getting or setting property values, ensuring data validation and encapsulation. Getters and setters use the get and set keywords respectively. Let's explore how to implement getters and setters in JavaScript classes and objects with practical examples. Syntax The basic syntax for getters and setters: class MyClass { ...

Read More
Showing 1–10 of 38 articles
« Prev 1 2 3 4 Next »
Advertisements