Javascript Articles

Page 375 of 534

Make HTML5 input type="number" accepting dashes

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 3K+ Views

To allow HTML5 input fields to accept dashes along with numbers, you cannot use type="number" directly since it only accepts numeric characters. Instead, use type="text" with a pattern attribute to validate the input format. The Problem with type="number" HTML5 input type="number" strictly accepts only numeric values and will reject any non-numeric characters including dashes. To accept dashes, we need to use type="text" with pattern validation. Solution Using Pattern Attribute Use the pattern attribute with a regular expression to validate numbers with dashes: Number Input with Dashes ...

Read More

Concatenating variable number of arrays into one - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 590 Views

We are required to write a JavaScript function that takes in any number of JavaScript arrays and returns one single array with all the values from input arrays concatenated into it. For example − If the input arrays are − [1, 5], [44, 67, 3], [2, 5], [7], [4], [3, 7], [6] Then the output should be − const output = [1, 5, 44, 67, 3, 2, 5, 7, 4, 3, 7, 6]; Using reduce() and concat() The most straightforward approach uses the reduce() method combined with concat() to merge ...

Read More

Test if the HTML attribute tabindex is present and get the value

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 533 Views

To test if the HTML attribute tabindex is present and get its value, you can use jQuery's attr() method or JavaScript's hasAttribute() method. Using jQuery attr() Method The attr() method returns the attribute value if it exists, or undefined if the attribute is not present: Element with tabindex Element without tabindex // Get tabindex value ...

Read More

Finding special array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 578 Views

An array is a special array if: - All the elements at odd indices are odd - All the elements at even indices are even We need to write a JavaScript function that takes an array and checks if it's a special array or not. Understanding the Logic For an array to be special: Index 0 (even): element must be even Index 1 (odd): element must be odd Index 2 (even): element must be even Index 3 (odd): element must be odd The key insight is that arr[i] % 2 should ...

Read More

HTML5 applicationCache vs Browser Cache

Nancy Den
Nancy Den
Updated on 15-Mar-2026 403 Views

HTML5 Application Cache and Browser Cache are two different caching mechanisms that serve distinct purposes in web development. Understanding their differences is crucial for optimizing web application performance. HTML5 Application Cache HTML5 Application Cache (AppCache) was a mechanism that allowed web applications to work offline by explicitly defining which resources should be cached. It used a manifest file to specify cacheable resources. // Example manifest file (cache.manifest) CACHE MANIFEST # Version 1.0 CACHE: index.html styles.css script.js logo.png NETWORK: * FALLBACK: / offline.html Browser Cache Browser cache is an automatic caching mechanism ...

Read More

Product of two number using HOC - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 317 Views

Higher Order Functions (HOC) in JavaScript are functions that either receive another function as an argument or return a function as their result. When combined with closures, HOCs become a powerful tool for creating reusable and modular code. In this example, we'll create a Higher Order Function that calculates the product of two numbers using the concept of currying, where a function returns another function. Example Here's how to implement a product calculator using HOC: const num1 = 24; const num2 = 5; const productHOC = num1 => { return ...

Read More

Frame by frame animation in HTML5 with canvas

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 835 Views

Frame by frame animation in HTML5 canvas creates smooth animations by displaying a sequence of images in rapid succession, similar to traditional flipbook animation. Basic Frame Animation Structure The core concept involves cycling through numbered image files and drawing them onto the canvas at regular intervals using setInterval(). Complete Example Frame Animation var canvas = document.getElementById('animationCanvas'); ...

Read More

Retrofit existing web page with mobile CSS

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 187 Views

To retrofit an existing web page for mobile devices, use CSS media queries to apply different styles based on device characteristics. This approach requires no server-side code and automatically handles various device types. Media queries allow you to target specific screen sizes, orientations, and device capabilities. They work by detecting browser and device properties, then applying appropriate CSS rules. Basic Mobile Media Query The most common approach targets screens with maximum widths for mobile devices: @media screen and (max-width: 768px) { body { ...

Read More

Checking Oddish and Evenish numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 306 Views

A number is Oddish if the sum of all of its digits is odd, and a number is Evenish if the sum of all of its digits is even. We need to write a function that determines whether a number is Oddish or Evenish. The function should return true for Oddish values and false for Evenish values. How It Works The algorithm extracts each digit from the number, adds them up, and checks if the sum is odd or even: Extract digits using modulo (num % 10) and integer division (Math.floor(num / 10)) Sum all ...

Read More

Get maximal GPS precision on mobile browser

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 315 Views

Getting accurate GPS location in mobile browsers requires understanding browser limitations and implementing best practices. Different browsers and devices provide varying levels of precision. Browser Limitations Built-in Android browsers restrict GPS accuracy for security and privacy reasons. Even when location permissions are granted, the precision may be limited to protect user privacy. Getting High Precision Location Use the Geolocation API with enableHighAccuracy option: GPS Precision Test Get High Precision Location ...

Read More
Showing 3741–3750 of 5,340 articles
« Prev 1 373 374 375 376 377 534 Next »
Advertisements