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
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to "enable" HTML5 elements in IE 8 that were inserted by AJAX call?
To enable HTML5 elements in IE 8 that were inserted by AJAX calls, you need to use plugins like html5shiv and manually create elements using document.createElement. The HTML5 Shiv enables use of HTML5 sectioning elements in legacy Internet Explorer and provides basic HTML5 styling for Internet Explorer 6-9. The Problem IE 8 doesn't recognize HTML5 elements like , , or . When these elements are inserted via AJAX, they won't render properly even with html5shiv loaded. Solution: Manual Element Creation You need to call document.createElement for each HTML5 element before inserting AJAX content: ...
Read MoreApply gravity between two or more objects in HTML5 Canvas
To apply gravity between two or more objects in HTML5 Canvas, you need to calculate the gravitational force between each pair of objects and update their velocities accordingly. Gravitational Force Formula The gravitational force between two objects is calculated using Newton's law of universal gravitation. In our simplified 2D canvas implementation, we use: F = G * (m1 * m2) / r² Where F is the force, G is the gravitational constant, m1 and m2 are the masses, and r is the distance between objects. Basic Gravity Calculation Here's how to calculate ...
Read MoreWrite a number array and using for loop add only even numbers in javascript?
In JavaScript, you can iterate through a number array and add only the even numbers using various loop methods. An even number is any integer that is divisible by 2, meaning when divided by 2, the remainder is 0. What are Even Numbers? Even numbers are integers that can be divided by 2 without leaving a remainder. We can check this using the modulo operator (%): if(number % 2 == 0) { // Number is even } Using for Loop The for loop is the most common way to iterate ...
Read MoreHow to access nested json objects in JavaScript?
Accessing nested JSON objects in JavaScript involves navigating through multiple levels of object properties. Nested objects are objects contained within other objects, creating a hierarchical data structure. What are Nested JSON Objects? A nested JSON object has one or more objects as property values. This creates multiple layers that you need to traverse to access specific data. Using Dot Notation The most common way to access nested properties is using dot notation, where you chain property names with dots. Example 1: Single Level Nesting var person = ...
Read MoreHow to get the code name and product name of the browser in JavaScript?
When a user accesses a web application, the JavaScript navigator object contains details about the browser they are currently using. Since each browser functions differently in how it interprets JavaScript, the navigator object helps in adapting your application to the user's browser preferences. The browser engine or product name can be accessed in JavaScript using the navigator.product property. However, in modern browsers, navigator.product always returns "Gecko" for compatibility reasons, regardless of the actual browser being used. Navigator.product Property Syntax navigator.product Example 1: Getting Browser Product Name This example demonstrates how to access ...
Read MoreHow to create a filter list with JavaScript?
JavaScript filter lists allow users to search and filter through data dynamically. This is commonly used for search functionality in websites and applications. Complete HTML Example * { box-sizing: border-box; } .searchInput { width: 100%; font-size: 16px; ...
Read MoreJavaScript Promises
Promises in JavaScript allow us to handle asynchronous operations where the value is not known in advance when the promise is being created. A promise can have three states: pending, fulfilled, and rejected. Promise States A promise represents an asynchronous operation and can be in one of three states: Pending: Initial state, neither fulfilled nor rejected Fulfilled: The operation completed successfully Rejected: The operation failed Creating a Basic Promise Here's how to create a simple promise: ...
Read MoreEffective Function Signatures with Default and Rest Parameters in JavaScript
JavaScript function signatures with default and rest parameters allow you to create flexible functions that handle variable arguments and provide fallback values when parameters are missing. Default Parameters Default parameters provide fallback values when arguments are undefined or not passed: Default Parameters function greet(name = "Guest", greeting = "Hello") { return `${greeting}, ...
Read MoreJavaScript Return the lowest index at which a value should be inserted into an array once it has been sorted (either in ascending or descending order).
We have to write a function that returns the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted (either in ascending or descending order). The returned value should be a number. For example, Let's say, we have a function getIndexToInsert() − getIndexToInsert([1, 2, 3, 4], 1.5, 'asc') should return 1 because it is greater than 1 (index 0), but less than 2 (index 1). Likewise, getIndexToInsert([20, 3, 5], 19, 'asc') should return 2 because once the array has been sorted in ...
Read MoreAppending a key value pair to an array of dictionary based on a condition in JavaScript?
In JavaScript, you can append key-value pairs to objects within an array or dictionary based on conditions using Object.assign() or the spread operator. This is useful when you need to add properties conditionally. Problem Statement Given a dictionary of student objects, we want to add a lastName property based on whether the student's name appears in a specific array. Using Object.assign() with Conditional Logic The following example demonstrates how to append a lastName property to each student object based on a condition: const details = { john: {'studentName': 'John'}, ...
Read More