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
-
Economics & Finance
Articles by Shubham Vora
Page 22 of 80
How to change the value of an attribute in javascript?
In JavaScript, changing attribute values dynamically allows you to create interactive web pages. Whether you need to modify styles, swap images, or update element properties, JavaScript provides several methods to manipulate HTML attributes. To change an attribute value, you first need to access the HTML element using methods like getElementById(), then modify the attribute directly or use methods like setAttribute(). Syntax Here are the main approaches to change attribute values: // Direct property access element.attribute = new_value; // Using setAttribute method element.setAttribute("attribute", "value"); Parameters attribute − The name of the ...
Read MoreHow to invoke a JavaScript Function as a method?
In this tutorial, we will learn how to invoke a JavaScript Function as a method. In JavaScript, the code inside a function will execute when the function is invoked. We can invoke a function in a variety of ways. One of them is using the method. The method is a property of an object that has a function value. We can define functions as object methods. This function will have a function name, a parameter (optional), and a return type (optional). It will have a "this" keyword which refers to an object. Users can follow the syntax below ...
Read MoreHow to convert an array into JavaScript string?
An array is the most popular and adaptable data structure you might employ in your regular programming. Converting an array into a JavaScript String can be done using several predefined methods and techniques. Using the toString() Method Using the join() Method Using JSON.stringify() Method Using Type Coercion Using the toString() Method The toString() method is a built-in JavaScript function that converts array elements into a comma-separated string. It's the simplest way to convert an array to string format. ...
Read MoreHow can we assign a function to a variable in JavaScript?
In this tutorial, we will learn to assign a function to a variable in JavaScript. Functions are reusable code blocks that can be stored in variables as expressions. There are two main ways to achieve this: using anonymous functions and arrow functions. Most JavaScript programmers are familiar with named functions, which follow this syntax: function function_name() { // function body } However, when we want to assign a function to a variable as an expression, we have two different approaches: Creating Anonymous Functions ...
Read MoreHow to get the value of PI in JavaScript?
In this tutorial, we will learn how to get the value of PI in JavaScript. The PI is a mathematical constant that is widely used in different sections of mathematics. It is defined by the ratio of the circumference of a circle to its diameter, which is approximately 3.14159. It is represented by the symbol '𝜋', which is a Greek letter. The value of PI is an irrational number, which means the value of the PI can't be expressed as a fraction, and the digits that came after the decimal are non-terminating and non-repeating. The value ...
Read MoreHow can we use a JavaScript function as an object?
This tutorial will teach us to use JavaScript functions as objects. In JavaScript, functions are first-class objects, meaning they can have properties and methods just like regular objects. This powerful feature allows us to create constructor functions that act as blueprints for creating multiple similar objects. The JavaScript object is an entity that contains key-value pairs with unique keys. Each key has values that can be of any type. We can access object values using their keys. We can create a function that behaves like an object using the this keyword and the new operator. Below is a ...
Read MoreHow to set the widths of the image border with JavaScript?
In this tutorial, we shall learn to set the widths of the image border with JavaScript. To set the widths of the image border, use the borderImageWidth property in JavaScript. When we need an image as a border of our webpage content, we have to see how to set the width of the image border. Using the Style borderImageWidth Property With the Style borderImageWidth property, we can set or return the widths of the image border of an element. The border image will range beyond the padding when the border image width is greater than the ...
Read MoreHow to set the amount by which the border image area extends beyond the border box with JavaScript?
In this tutorial, we will learn how to set the amount by which the border image area extends beyond the border box in JavaScript. To set the amount by which the border image is extended, you need to set the border outside edges. To do this we can apply the borderImageOutset style property provided in JavaScript. After creating a border image area for the HTML element, we might have to increase the area. By knowing a method to increase the border image area more than the border box, we can make the change without writing lengthy code. Using ...
Read MoreHow to get the arccosine (in radians) of a number in JavaScript?
This tutorial will help you to find the arccosine in radians of a number in JavaScript. Cosine is the ratio of the adjacent side and the hypotenuse of the right-angled triangle. To get the cosine of a number, the Math.cos() function is used in JavaScript. The value returned will be between -1 and 1. The inverse of cosine is called arccosine. An angle's trigonometric arccosine value can be calculated using the Math.acos() method. This returns a value between 0 and π (pi). The input to acos() must be between -1 and 1 inclusive. The function returns the ...
Read MoreHow to pass an object as a parameter in JavaScript function?
In this tutorial, we will learn how to pass an object as a parameter in a JavaScript function. One of JavaScript's data types is represented by the Object type. It is used to store keyed collections as well as more complex entities. The Object() constructor or the object initializer / literal syntax can be used to create objects. Almost all JavaScript objects are instances of Object; a typical object inherits properties (including methods) from Object.prototype, though these properties may be shadowed (a.k.a. overridden). Following are the methods used to pass an object as a parameter in a ...
Read More