Lokesh Yadav

Lokesh Yadav

38 Articles Published

Articles by Lokesh Yadav

Page 2 of 4

Sibling of a list element in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 6K+ Views

In this article, we are going to learn about the sibling of a list element in JavaScript with suitable examples. To find the sibling of a list element in JavaScript, there is an existing property called nextSibling. The nextSibling property returns the next node on the same tree level. The nextSibling returns a node object and it is a read-only property. Note − The nextSibling propery returns the next sibling node: An element node, a comment node, a text node. The whitespaces in between the elements are also considered as text nodes. Now, Let’s look into the syntax and usage ...

Read More

Insert a specified element in a specified position in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 2K+ Views

The given task to perform in this article is to insert a specified element in a specified position in JavaScript. The Javascript has provided "insertAdjacentElement()" to insert an already existing element in a specified position. There are four specified legal positions. The first position is ‘afterbegin’ (After the beginning of the element (first child)), the second is ‘afterend’ (After the element), third is ‘beforebegin’ (Before the element) and the fourth legal position is ‘beforeend’ (Before the end of the element (last child)). If there are multiple elements with the same name, then use indexes to access them as we access ...

Read More

Insert a specified HTML text into a specified position in the JavaScript document?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 1K+ Views

In this article, we are going to learn how to insert a specified HTML text into a specified position in the JavaScript document with suitable examples. There is an existing method in the JavaScript to insert a specified HTML text into a specified position in the JavaScript document i.e. insertAdjacentHTML() method. There are four specified legal positions. The first position is ‘afterbegin’, the second is ‘afterend’, third is ‘beforebegin’ and the fourth legal position is ‘beforeend’. Let’s use the above discussed specified legal postions in the examples below. Syntax The syntax to insert a specified HTML text into a specified ...

Read More

An element inside another element in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 10K+ Views

In this article, we are going to discuss about an element inside another element in JavaScript with suitable examples. In JavaScript to access an element within another element i.e.., the inner element, we use ‘.’ property. We can also check whether an element is present within another element or not using contains() method. This method either returns true or false. Let’s look into the possible ways to check an element inside another element with appropriate examples further in this article. Syntax The syntax to access an element inside another element is − document.getElementById(‘IDname’).getElementsByTagName(‘Tag’)[i].innerHTML; Where, IDname is the name ...

Read More

Replace a child node with a new node in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 3K+ Views

In this article we are going to learn how to replace a chils node with a new node in JavaScript with suitable examples. To replace a child node with a new node, there is an inbuilt method to replace the new node with the old node within a given parent node. The inbuilt methods are – replaceChild(), replaceWith(). The methods replaceChild(), replaceWith() are supported by all modern browsers and also they are features of DOM Level1. To understand this concept better, let’s look into the syntax and usage of replaceChild() and replaceWith() methods in JavaScript. Syntax The syntax for replaceChild() ...

Read More

Number of elements a particular tag contains in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 1K+ Views

In this article we are going to learn about the number of elements a particular tag contains in JavaScript with suitable examples. There are two possible ways to find the number of elements a particular tag contains in JavaScript. One of the possible way is to use the existing property childElementCount and the other way is to use the length property of JavaScript. To understand better, Let’s look into the examples which achieved the above task by using childElementCount and length property of JavaScript. Using the childElementCount property The childElementProperty will return the number of elements a particular id tag ...

Read More

Built-in javascript constructors?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 1K+ Views

In this article, we are going to discuss about the Built-in JavaScript constructors with appropriate examples in JavaScript. Javascript has provided some built-in constructors for native objects. These built-in functions include Object(), String(), Boolean(), RegExp(), Number(), Array(), Function(), Date(). Note We cannot include Math object in those built-in constructors because Math is a global object. The 'new' keyword cannot be used with Math. Let’s understand this concept in a better way with the help of examples further in this article. Example 1 This is an example program to illustrate about the inbuilt constructor String(). ...

Read More

Add a property to a JavaScript object constructor?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 913 Views

In this article, we’ll go over how to add a property to a JavaScript object constructor in JavaScript with appropriate examples. Adding a property to an object constructor is different from adding a property to a normal object. If we want to add a property, we have to add it in the constructor itself rather than outside the constructor whereas we can add anywhere in a normal object. To get a better understanding of the given task, let’s look into the syntax and usage of the constructor in JavaScript. Syntax The syntax for a constructor is − Constructor(); // No ...

Read More

How to add a method to a JavaScript object?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 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. Syntax The syntax ...

Read More

How to encode a string in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 09-Dec-2022 27K+ Views

In this article we are going to learn how to encode a string in JavaScript with appropriate examples. Encoding is the process of converting from one data format to another format. In computer science terms, encoding is the process of converting a text into a cipher text. Encoding is different from the Encryption process. The difference between encoding and encryption is where the encoding is used to keep data usable and data confidentiality is maintained by encryption. Encoding does not use a key for encoding process whereas for encryption there should be a key for encryption process. The methods that ...

Read More
Showing 11–20 of 38 articles
Advertisements