Found 6685 Articles for Javascript

How can a page be forced to load another page in JavaScript?

Tarun Singh
Updated on 23-Feb-2023 13:57:25

6K+ Views

In JavaScript, we can use window.location object to force a page to load another page. We can use the location object to set the URL of a new page. There are different ways – window.location.href property, window.location.assign() and window.location.replace() methods, to set the URL of a new page using the location object. We will discuss each of the property and methods in detail in this tutorial. Window.location.replace The first way is to use the window.location.href property. This property contains information about the current URL of the page, and it can be used to redirect the user to a new page. ... Read More

How are the JavaScript window and JavaScript document different from one another?

Tarun Singh
Updated on 24-Jul-2023 10:17:41

177 Views

In JavaScript, the window object represents the current web browser window, while the document object represents the web page that is currently loaded in the window. The window object in JavaScript provides access to the browser's history, location, and other properties and methods that allow us to interact with the browser window itself. It contains information about the browser window, like the size, the document the window contains, and the window’s history. The document object represents the structure of the web page as a whole and provides access to the content of the page, as well as methods for manipulating ... Read More

How to use an HTTP GET or POST for Ajax Calls?

Rushi Javiya
Updated on 22-Feb-2023 15:19:39

7K+ Views

We need to use JavaScript, and an AJAX library like jQuery, Axios, or Fetch API to make an AJAX call using HTTP GET or POST. Ajax (Asynchronous JavaScript and XML) creates fast and dynamic web pages by updating content asynchronously without reloading the entire page. It uses JavaScript to send and receive data from a server, which can be in the form of XML, JSON, or plain text. This tutorial will teach us to use an HTTP GET or POST for Ajax Calls. Ajax has two common types of requests: GET and POST. GET Request The GET request is ... Read More

How to Sort/Order keys in JavaScript objects ?

Rushi Javiya
Updated on 22-Feb-2023 15:14:58

13K+ Views

In JavaScript, an object contains the key-value pair. Sometimes, we may require to sort the object keys. We can’t use the sort() method directly with the object as like array, as we need to sort the key-value pair of the object together rather than sorting only keys. Below, we will learn various methods to sort the object keys in ascending and descending order. Use the sort() method to order keys in JavaScript objects We can use the Object.keys() method to get all keys of the object in the array. After that, we can use the array.sort() method to sort ... Read More

How to sort rows in a table using JavaScript?

Rushi Javiya
Updated on 22-Feb-2023 15:13:02

2K+ Views

We can’t use the built-in sort() method of JavaScript to sort the table rows based on the particular column. So, we need to create a custom algorithm to sort table rows. In this tutorial, we will learn to sort tables and rows using JavaScript. Here, we will look at different examples to sort table rows in ascending and descending order. Syntax Users can follow the syntax below to sort rows in a table using JavaScript. var switchContinue = true; while (switchContinue) { switchContinue = false; var allRows = table.rows; for ... Read More

How to solve JavaScript heap out of memory on prime number?

Rushi Javiya
Updated on 22-Feb-2023 17:58:44

175 Views

As the ‘heap out of memory’ error message suggests, it occurs when any JavaScript code takes more memory than allocated memory, when we run any JavaScript program, the computer allocation particular memory to the JavaScript program. When we run code of JavaScript or any programming language, our computer creates a process and allocates fixed memory. When a program needs more memory size, it raises an error like heap out of memory. For example, if we create an array of size 1020 and try to initialize every array index with some value, the heap goes out of memory and raises ... Read More

How to set default values when destructuring an object in JavaScript?

Rushi Javiya
Updated on 22-Feb-2023 15:04:45

5K+ Views

The array and object destructuring feature was introduced in the ES6 version of JavaScript. The destructuring of the array and object allows us to store its values in a separate variable. After that, we can use that variable to access the value of the particular property of the object. The main thing we need to focus on while destructuring the array object is the default values. For example, we have added the property3 variable in the destructuring object, but if the object doesn’t contain the property3, destructuring sets the undefined value to the property3 variable. Users can follow ... Read More

How to set cursor style to pointer for links without href?

Rushi Javiya
Updated on 22-Feb-2023 15:03:05

2K+ Views

We can use the tag in HTML to add a link to the web page. The default cursor style for the elements is the pointer, but removing the href attribute from the tag changes the cursor style. So, in this tutorial, we will learn to keep the cursor style to pointer for tags without the href attribute. Users can follow the example below to check out the default cursor style for the elements Example In the example below, we have used the tag to create three different links. In the output, we ... Read More

How to set cursor position in content-editable element using JavaScript?

Rushi Javiya
Updated on 22-Feb-2023 15:00:56

9K+ Views

In HTML, content editable div allows users to edit the content of the div element. We need to pass the contenteditable attribute with true Boolean value to the div element to make any div element editable. The content editable div contains the caret cursor by default, and sometimes we may require to set the caret cursor position in the content editable div element to edit the content of the div. However, we can set the caret cursor position anywhere by clicking at a particular place in the content editable div. This tutorial will teach us to use different ... Read More

How to send row data when clicking the button using javascript?

Rushi Javiya
Updated on 22-Feb-2023 14:59:49

8K+ Views

The table contains multiple rows, and every row contains multiple columns. Also, every column contains multiple HTML elements or texts. Here, we will add the submit button on every table row, and based on the button click, we will access the row's data. We will use JavaScript and jQuery to access the row data, and after that, users can send it anywhere, wherever they want, using API, etc. Use JavaScript to access row data In this approach, we will access the first clicked element. We will find its parent element based on the clicked element, giving us a particular ... Read More

Advertisements