Found 8894 Articles for Front End Technology

How to check the current runtime environment is a browser in JavaScript?

Prince Varshney
Updated on 26-Jul-2022 08:38:51

3K+ Views

A runtime environment is an environment where your code will be executed. It tells what global objects your code can access and it also impacts its result. A JavaScript code can run in different types of environments some of them are Node.js, Service Workers, or in a web browser. So, to start coding in JavaScript, you don’t have to install any additional software. Each web browser comes with a JavaScript engine. You can simply run scripts you write inside any browser but it ensures that it follows all the rules of the ECMAScript (ES6) functionality.Here we will detect in which ... Read More

How to print colored text in the console using JavaScript?

Prince Varshney
Updated on 21-Jul-2022 13:24:02

2K+ Views

In this article, we will learn how to add colors to the text and print them in the console window of JavaScript. In the original, all the data printed in the console is of black color no other color is reflected in the console but here we are going to add some special characters with text to make our console window look more colorful.There are some special codes that help change in color of the output in the console window and these codes are known as ANSI escape codes. By adding these codes in the console.log() method we can see ... Read More

What is JavaScript Error Constructor?

Prince Varshney
Updated on 21-Jul-2022 10:20:05

995 Views

A JavaScript constructor is a function that creates and initializes an object instance of a class. A constructor is used to create a new object and set values for existing object properties. The Error() constructor in JavaScript is used to create new error objects. Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. See below for standard built-in error types.SyntaxFollowing is the syntax for an Error( ) constructor −new Error() new Error(message) new Error(message, options) new Error(message, fileName) new Error(message, fileName, lineNumber)The Error() constructor can be defined ... Read More

How to replace line breaks with
using JavaScript?

Prince Varshney
Updated on 21-Jul-2022 09:57:07

3K+ Views

In this tutorial, we are going to learn how to replace all the line breaks in JavaScript code using a tag. There are various methods using which we can replace all the line breaks with tag. Some of the methods are given below −Using String replace() Method and RegExIn this method we are using the String.replace() method to replace all the line breaks in the plain text with the tag. Here the RegEx refers to the regular expression that we write inside the string.replace() method.SyntaxFollowing is the syntax to use replace() method −sentence.replace(/(?:\r|\r|)/g, "");Here sentence is the string ... Read More

How to register a handler to be called when the Ajax request begins using jQuery?

Manav Sarkar
Updated on 20-Jul-2022 12:44:56

453 Views

jQuery is a feature-rich JavaScript library. We can perform a lot of actions with the help of jQuery which would otherwise require writing large pieces of code. It makes DOM manipulation, event handling, animation, ajax, etc. very easy.In this tutorial, we will learn how to register a handler to be called when the first Ajax request begins using jQuery. Ajax requests are typically HTTP requests that are called by the browser for different tasks such as GET, POST, etc. So when the tasks are performed, we can register a handler using the ajaxStart() function of jQuery. This function is always ... Read More

How to register a handler to be called when all Ajax requests completed using jQuery?

Manav Sarkar
Updated on 20-Jul-2022 12:37:08

328 Views

In this tutorial, we will learn how to register a handler to be called when all Ajax requests are completed using jQuery. Ajax requests are typically HTTP requests that are called by the browser for different tasks such as GET, POST, etc. So when the tasks are performed, we can register a handler using the ,ajaxStop() function of jQuery.SyntaxUse the following syntax to register a handler after an ajax request −$(document).ajaxStop(function () {    console.log('Registered handler.') })Explanation − Suppose we have a GET request on an API. When the API returns a result, jQuery checks if any requests are pending ... Read More

How to register a handler to be called when all Ajax requests completed using jQuery?

Manav Sarkar
Updated on 20-Jul-2022 12:32:25

886 Views

In this tutorial, we will learn how to register a handler to be called when Ajax requests complete using jQuery. Ajax requests are typically HTTP requests that are called by the browser for different tasks such as GET, POST, etc. So when the tasks are performed, we can register a handler using the ajaxComplete() function of jQuery. This function is always triggered when the request is completed.SyntaxUse the following syntax to register a handler after every ajax request −$(document).ajaxComplete(function () {    console.log('Registered handler.') })Explanation − Suppose we have a GET request on an API. When the API returns a ... Read More

How to check the lock state of a callback list using jQuery?

Manav Sarkar
Updated on 20-Jul-2022 12:18:54

118 Views

In this tutorial, we will learn how to check the lock-state of a callback list using jQuery. The lock is a callback list in jQuery in the current state. We can toggle the lock state so that additional changes cannot be made unless required.SyntaxThe callbacks list is locked and checked as follows −// Get callbacks list at current state var callbacks = $.Callbacks() // Lock the callbacks list callbacks.lock() // Check callbacks is locked or not console.log(callbacks.locked())AlgorithmFirst we receive the callbacks list at the current state using the Callbacks() function.Then we lock it using the lock() function and ... Read More

How to attach a function to be executed before an Ajax request is sent using jQuery?

Manav Sarkar
Updated on 20-Jul-2022 09:29:30

1K+ Views

In this tutorial, we will learn How to attach a function to be executed before an Ajax request is sent using jQuery. Ajax requests are typically HTTP requests that are called by the browser for different tasks such as GET, POST, etc. So when the tasks are performed, we can register a handler using the ajaxSend() function of jQuery. This event is called by jQuery whenever an ajax request is to be made.SyntaxUse the following syntax to register a handler before an ajax request −$(document).ajaxSend(function () {    console.log('Triggered ajaxStart. Started Request') })We have an Ajax request. Before sending the ... Read More

How to add the previous set of elements on the stack to the current set in jQuery?

Manav Sarkar
Updated on 19-Jul-2022 13:00:27

192 Views

jQuery is a feature-rich JavaScript library. We can perform a lot of actions with the help of jQuery which would otherwise require writing large pieces of code. It makes DOM manipulation, event handling, animation, ajax, etc. very easy.In this tutorial, we will learn to add the previous set of elements on the stack to the current set. jQuery maintains an internal stack of the changes that are performed to the matched stack. When the DOM traversal functions or methods are called, the new elements are pushed into the stack. So to use previous stack elements, the addBack() method is called.SyntaxWe ... Read More

Advertisements