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
Programming Articles
Page 886 of 2547
How to stop form submission using JavaScript?
In this tutorial, we will see the methods to stop form submission using JavaScript. Generally, the HTML form by default submits automatically when certain events are triggered. The automatic submission causes the browser to refresh and reload the whole page, which we don't want in some cases. To perform any operation before submission, we need to change the default behavior of the form to prevent it from submitting. Following are the methods we can use to stop form submission: Using the "return false" value Using the preventDefault() method Let ...
Read MoreHow to display output in javascript?
JavaScript provides several methods to display output to users. Here are the four most common approaches for displaying data in web applications. Using innerHTML to Display in HTML Elements The innerHTML property allows you to insert content directly into HTML elements on your webpage. document.getElementById("demo").innerHTML = "Hello, World!"; Hello, World! Using document.write() Method The document.write() method writes content directly to the HTML document. ...
Read MoreWrite the syntax of javascript with a code to demonstrate it?
JavaScript Tags JavaScript code must be placed within HTML tags to execute properly. These script tags can be positioned in different locations within an HTML document. Where to Place JavaScript JavaScript can be embedded in three main locations: Head section: Scripts in the tag load before the page content Body section: Scripts in the tag execute as the page loads External file: Scripts can be linked from separate .js files Basic JavaScript Syntax JavaScript syntax includes variables, functions, and DOM ...
Read MoreWhat are the types of tags involved in javascript?
In JavaScript, there are several types of HTML tags that work with JavaScript code. The most important is the tag, which is essential for embedding or linking JavaScript in web pages. HTML Tag The tag is used to define client-side scripts in HTML documents. It can contain JavaScript code directly or reference an external JavaScript file. All JavaScript code must be placed within tags to be executed by the browser. Types of Script Tags Inline JavaScript JavaScript code written directly inside the tag: ...
Read MoreWhat is the difference between Math.ceil() and Math.round() methods in JavaScript?
Math.ceil() and Math.round() are JavaScript methods that round numbers to integers, but they work differently. Math.ceil() always rounds up to the nearest integer, while Math.round() rounds to the nearest integer using standard rounding rules (0.5 and above rounds up, below 0.5 rounds down). Math.ceil() - Always Rounds Up The Math.ceil() method rounds a number up to the nearest integer, regardless of the decimal value. It always moves toward the greater value. Syntax Math.ceil(x) Example ...
Read MoreHow do we include the direction of text display in HTML?
Use the dir attribute in HTML to specify the text direction. This attribute controls whether text flows left-to-right (LTR) or right-to-left (RTL). Syntax content Attribute Values Value Description Use Case ltr Left-to-right English, French, German rtl Right-to-left Arabic, Hebrew, Urdu auto Browser determines direction Mixed language content Example Here's how to use the dir attribute for different text directions: Text Direction Example This is default left-to-right text. ...
Read MoreWhat is function chaining in JavaScript?
Function chaining is a technique that allows you to call multiple methods on the same object in sequence using dot notation. This makes code more concise and improves readability by eliminating the need to repeatedly reference the same object. How Function Chaining Works For function chaining to work, each method must return the object itself (typically using return this). This allows the next method in the chain to be called on the returned object. Without Function Chaining In this example, the methods don't return this, so chaining is not possible: ...
Read MoreExplain in detail about the memory life cycle of JavaScript?
JavaScript's memory management is crucial for application performance. Understanding the memory lifecycle helps developers write more efficient code and avoid memory leaks. The Three Stages of Memory Lifecycle Every programming language follows a similar memory lifecycle with three fundamental stages: Allocation of memory - Reserve memory space for variables and objects Use the allocated memory - Read from and write to the allocated memory Release the allocated memory - Free up memory when it's no longer needed In low-level languages, developers manually handle allocation and deallocation. However, high-level languages like JavaScript manage this process ...
Read MoreHow to execute a cube of numbers of a given array in JavaScript?
To calculate the cube of each number in an array, you can use several approaches. The most common methods involve iterating through the array and applying the cube operation (n³) to each element. Using a for Loop The traditional approach uses a for loop to iterate through the array and replace each element with its cube: var numbers = [1, 2, 3, 4, 5]; // Calculate cube of each element for (var i = 0; i ...
Read MoreHow to get a part of string after a specified character in JavaScript?
To get a part of a string after a specified character in JavaScript, you can use the substring() method combined with indexOf(). This technique allows you to extract portions of text before or after any character. Understanding substring() The substring() method extracts characters from a string between two specified indices. It takes a start index (inclusive) and an optional end index (exclusive). Syntax for Getting Text After a Character string.substring(string.indexOf(character) + 1); Here, indexOf(character) finds the position of the character, and adding + 1 starts extraction from the next position. Syntax for ...
Read More