Found 6683 Articles for Javascript

How to convert a currency string to a double with jQuery or JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:59:20

3K+ Views

If you are working with currency values in your web application, it is important to convert them from a string representation into an actual numerical value. In this article, we will discuss how to do this using both jQuery and JavaScript. We will look at the different methods available for converting strings to doubles. There are two popular ways to convert currency string into float string using different JavaScript inbuilt libraries. Let’s look into the following article to understand more about how to convert a currency string to a double with jQuery or JavaScript. This is a straightforward way in ... Read More

Detecting arrow key presses in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:56:27

17K+ Views

In this article we are going to learn about detecting arrow key presses in JavaScript. Before we jump into the article, let’s discuss few things to know some information. There is a distinct key code for each key on the keyboard. Here, we'll check to see if the arrow key has been pressed. There are four arrow keys on our keyboard. On our keyboard, we can see, the left, right, up, and download keys. These keys also have a special key code that JavaScript can utilise to determine whether, or not they have been depressed. The key codes for the ... Read More

Remove all child elements of a DOM node in JavaScript?

AmitDiwan
Updated on 27-Oct-2020 09:58:58

217 Views

To remove child elements, set the innerHTML to ‘’.ExampleFollowing is the code −            Document Javascript MySQL Remove the items    remove.onclick = () => {       const element = document.getElementById("removeAllChildElements");       element.innerHTML = '';    } To run the above program, save the file name anyName.html(index.html). Right click on the file and select the option “Open with live server” in VS Code editor.OutputThis will produce the following output −Now you can click the button “Remove the items”. It will remove all the elements inside the box.OutputThis will produce the following output −

JavaScript map() is not saving the new elements?

AmitDiwan
Updated on 27-Oct-2020 09:55:09

97 Views

Use the map() function correctly to save elements.ExampleFollowing is the code −const addIndexValueToArrayElement = function (arrObject) {    const updatedArrayValue = [];    arrObject.forEach(function (ob) {       const mapValue = ob.map(function (value) {          return value + arrObject.indexOf(ob)       })       updatedArrayValue.push(mapValue)    })    return updatedArrayValue; }; const output = addIndexValueToArrayElement([    [4, 5],    [7, 56],    [34, 78], ]); console.log(output);To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo323.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo323.js [ [ 4, 5 ], [ 8, 57 ], [ 36, 80 ] ]

JavaScript input type=submit is not working?

AmitDiwan
Updated on 27-Oct-2020 09:53:50

1K+ Views

To make it work, you can use onclick with input type = “submit”.ExampleFollowing is the code −            Document           First Name:             Submit        var firstName = null;    function submitForm(evnt) {       evnt.preventDefault();       firstName = document.getElementById("fName").value;       document.getElementById("result").innerHTML = "The First Name is=" + firstName;    } To run the above program, save the file name anyName.html(index.html). Right click on the file and select ... Read More

How to get the entire document HTML as a string in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:55:12

2K+ Views

One of the most useful features of JavaScript is the ability to get an entire document's HTML as a string. This can be used for many purposes, such as obtaining data from a website or creating dynamic content on your own website. In this article, we'll go over how to get the entire document HTML as a string in JavaScript. To get the entire document HTML as a string, use the concept of innerHTML The dynamic html can be written on the html document using the innerHTML property. The majority of the time, it is used in web pages to ... Read More

How can I get H1 innerText in JavaScript without the innerText of its child?

Yaswanth Varma
Updated on 18-Jan-2023 11:15:13

2K+ Views

Getting the inner text of an HTML element is a common task when developing web applications. In JavaScript, it can be done using the innerText property of the HTMLElement object. However, this only returns the text within that particular element and not any of its child elements. If you need to get just the H1 tag's innertext without including its child elements' innertext, then there are several ways to do so. This article will discuss some methods for getting an H1 tag's innertext in JavaScript without including its child elements' innertext. The rendered text content of a node, and ... Read More

JavaScript display the result of a function as HTML?

Yaswanth Varma
Updated on 18-Jan-2023 11:12:18

3K+ Views

In this article we are going to learn about JavaScript display the result of a function as HTML. In JavaScript, a function is similar to a procedure—a collection of statements that carry out an action or compute a value. However, in order for a procedure to be considered a function, it must accept an input and produce an output with an obvious connection between the input and the output. Syntax Following is the syntax for function in JavaScript function name(parameter1, parameter2, parameter3) { // code to be executed } let’s dive into the article to learn ... Read More

Remove element by id in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:52:23

6K+ Views

The Remove Element By Id In JavaScript method is a powerful tool for manipulating the DOM (Document Object Model). It allows you to remove elements from the page by their id. This can be useful when removing unwanted elements or creating dynamic content on the fly. The syntax is simple, and this article will explain how to use it in more detail. In order to make a website interactive, JavaScript provides it with a number of functionalities. Removing a node or an element from a web page is one of the most fundamental features offered by JavaScript. Let's go over ... Read More

Repeat String in JavaScript?

AmitDiwan
Updated on 27-Oct-2020 09:40:39

114 Views

To repeat string, you can use Array() along with join().ExampleFollowing is the code −            Document    String.prototype.counter = function (value) {       return new Array(value + 1).join(this);    }    console.log("The repeat string".counter(5)); To run the above program, save the file name anyName.html(index.html). Right click on the file and select the option “Open with live server” in VS Code editor.OutputThis will produce the following output: on console −

Advertisements