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
Javascript Articles
Page 287 of 534
How to convert a decimal number to roman using JavaScript?
Roman numerals are a number system that uses letters from the Latin alphabet to represent values. In this tutorial, you'll learn how to convert decimal numbers to Roman numerals using JavaScript. Roman Numeral Symbols Seven basic symbols form Roman numerals: I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1000 Additionally, subtractive combinations are used for specific values: IV = 4 IX = 9 XL = 40 XC = 90 CD = 400 CM = 900 Algorithm The ...
Read MoreHow to deal with floating point number precision in JavaScript?
Floating point precision issues occur when JavaScript cannot exactly represent certain decimal numbers in binary format. Common problems include 0.1 + 0.2 = 0.30000000000000004. JavaScript provides several methods to handle these precision issues. The Floating Point Problem JavaScript uses IEEE 754 double-precision floating-point format, which can cause unexpected results: console.log(0.1 + 0.2); // 0.30000000000000004 console.log(0.1 + 0.2 === 0.3); // false ...
Read MoreClass Selectors in CSS
You can define style rules based on the class attribute of the elements. All the elements having that class will be formatted according to the defined rule. Basic Class Selector Syntax Class selectors start with a dot (.) followed by the class name: .black { color: #808000; } This rule renders the content in olive color for every element with class attribute set to "black" in the document. Element-Specific Class Selectors You can make class selectors more specific by combining them with element selectors: h1.black { ...
Read MoreHow to split JavaScript Number into individual digits?
In this tutorial, we will learn how to split a JavaScript number into individual digits. This technique is useful for tasks like checking palindrome numbers, finding digit sums, or analyzing number patterns. We'll explore three different approaches based on the input format: Using modulo operator for numeric input Using array push() method for string input Using string split() method for string input Method 1: Using Modulo Operator (Numeric Input) When the input is a number, we can use the modulo (%) operator with division to extract digits from right to left. Syntax ...
Read MoreHow to test if a JavaScript cookie has expired?
To test if a JavaScript cookie has expired, you need to check if the cookie exists or returns null. When a cookie expires, the browser automatically removes it, so attempting to access it will return null or undefined. Using document.cookie (Vanilla JavaScript) The most straightforward approach is to create a helper function that checks if a cookie exists: function getCookie(name) { const cookies = document.cookie.split(';'); for (let cookie of cookies) { const [cookieName, cookieValue] = cookie.trim().split('='); ...
Read MoreUsage of text-transform property in CSS
The text-transform property in CSS is used to control the capitalization of text content. It allows you to transform text to uppercase, lowercase, capitalize first letters, or leave it unchanged. Syntax text-transform: value; Property Values Value Description none No transformation (default) capitalize Capitalizes the first letter of each word uppercase Converts all text to uppercase lowercase Converts all text to lowercase Example Text Transform Example ...
Read MoreHow I can set the width and height of a JavaScript alert box?
JavaScript's native alert() function creates a browser-controlled dialog box whose size cannot be customized. To set the width and height of an alert box, you need to create a custom alert dialog using HTML, CSS, and JavaScript. Why Native alert() Cannot Be Resized The browser's built-in alert() function creates a modal dialog with fixed dimensions determined by the browser and operating system. These native alerts cannot be styled or resized using CSS or JavaScript. Creating a Custom Alert Box Here's how to create a customizable alert box with specific width and height dimensions using jQuery: ...
Read MoreHow I can show JavaScript alert box in the middle of the screen?
The native JavaScript alert() box cannot be repositioned as its styling and position are controlled by the browser. To show an alert box in the center of the screen, you need to create a custom alert dialog using HTML, CSS, and JavaScript. Why Native alert() Can't Be Centered The built-in alert() function displays a browser-controlled modal that appears at a fixed position determined by the browser, typically near the top of the viewport. This position cannot be customized through CSS or JavaScript. Creating a Custom Centered Alert Box Here's how to create a custom alert that ...
Read MoreHow to customize the position of an alert box using JavaScript?
To customize the position of an alert box, you need to create a custom alert since the native JavaScript alert() function cannot be positioned. We can build a custom alert box using HTML, CSS, and JavaScript, then control its position using CSS properties like top and left. Creating a Custom Alert Box The native alert() box position is controlled by the browser and cannot be customized. Instead, we create a custom modal dialog that mimics an alert box behavior. Example: Custom Positioned Alert Here's how to create a custom alert box with customizable positioning: ...
Read MoreExample of embedded CSS
Embedded CSS allows you to place CSS rules directly within an HTML document using the element. This tag is placed inside the section, and the rules defined will apply to all elements in the document. Syntax /* CSS rules go here */ selector { property: value; } ...
Read More