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 by Ramu Prasad
48 articles
How to create a context menu for an element in HTML5?
The contextmenu attribute in HTML5 was designed to create custom context menus for elements that appear when a user right-clicks. However, this feature has been deprecated and removed from modern browsers due to security and usability concerns. Syntax The original syntax for the contextmenu attribute was − Content Where menu-id is the ID of the associated element with type="context". Original HTML5 Implementation (Deprecated) The contextmenu attribute was intended to work with the and elements to create custom right-click menus. ...
Read MoreUsage of color property in CSS
The color property in CSS is used to set the color of text content. It accepts various color formats including color names, hexadecimal values, RGB, and HSL values. Syntax color: value; Color Value Formats The color property accepts several formats: Color names: red, blue, green, etc. Hexadecimal: #ff0000, #00ff00, #0000ff RGB: rgb(255, 0, 0) RGBA: rgba(255, 0, 0, 0.5) with transparency HSL: hsl(0, 100%, 50%) Example: Using Color Names ...
Read MoreHow to fix Array indexOf() in JavaScript for Internet Explorer browsers?
Internet Explorer versions 8 and below don't support the Array.indexOf() method. This article shows how to fix this compatibility issue using polyfills and jQuery alternatives. The Problem In modern browsers, indexOf() returns the first index of an element in an array, or -1 if not found. However, IE8 and earlier throw an error when you try to use this method. Method 1: Using Array Polyfill Add this polyfill to support indexOf() in older IE browsers: Method 2: Using jQuery.inArray() jQuery provides a cross-browser alternative with jQuery.inArray(): // Syntax: ...
Read MoreHow to set the capitalization of a text with JavaScript?
To set the capitalization, use the textTransform property in JavaScript. Set it to capitalize, if you want the first letter of every word to be a capital letter. Syntax element.style.textTransform = "value"; The textTransform property accepts these values: capitalize - Capitalizes the first letter of each word uppercase - Converts all text to uppercase lowercase - Converts all text to lowercase none - Removes any text transformation Example: Capitalizing Text You can try to run the following code to capitalize text with JavaScript: ...
Read MoreWhy does the JavaScript need to start with ";"?
JavaScript uses semicolons (;) to separate statements and avoid potential issues with automatic semicolon insertion (ASI). Starting lines with semicolons is a defensive programming practice. The Problem Without Semicolons JavaScript automatically inserts semicolons at line breaks, but this can cause unexpected behavior when lines are concatenated: // Without defensive semicolon let result = getValue() (function() { console.log("This might not work as expected"); })(); function getValue() { return "Hello"; } JavaScript interprets this as calling getValue() with a function as an argument, which causes an error. ...
Read MoreHow to create a zero-filled JavaScript array?
To create a zero-filled JavaScript array, you have several methods available. The most common approaches include using Array.fill(), Array.from(), or typed arrays like Uint8Array. Using Array.fill() Method The Array.fill() method is the most straightforward way to create a zero-filled array: // Create array of length 5 filled with zeros var zeroArray = new Array(5).fill(0); document.write("Zero-filled array: " ...
Read MoreHow to compare two JavaScript Date Objects?
JavaScript Date objects can be compared directly using comparison operators (>, =, date2) { document.write("Current date is more recent."); } else { document.write("Custom date is more recent."); } Current date: Mon May 28 2018 09:48:49 GMT+0530 (India Standard Time) Custom date: Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time) Current date is more recent. Comparing for ...
Read MoreHow to reduce the number of errors in scripts?
Reducing errors in JavaScript scripts is crucial for maintainable code. Following established best practices can significantly improve code quality and reduce debugging time. Essential Practices for Error-Free Scripts Use Meaningful Comments Comments explain the purpose and logic behind your code, making it easier to understand and maintain. // Calculate total price including tax function calculateTotal(price, taxRate) { // Apply tax rate as percentage const tax = price * (taxRate / 100); return price + tax; } console.log(calculateTotal(100, 8.5)); // $100 with 8.5% ...
Read MoreHow to get the list of document properties which can be accessed using W3C DOM?
The Document Object Model (DOM) provides several key properties that allow you to access and manipulate different parts of an HTML document. These properties are standardized by the W3C and are available across all modern browsers. Core Document Properties Here are the essential document properties you can access using the W3C DOM: Property Description & Example ...
Read MoreHow to search the querystring part of the href attribute of an area in JavaScript?
To get the querystring from the href attribute of an area element, use the search property. This property returns the query portion of the URL, including the question mark. Syntax areaElement.search Return Value Returns a string containing the query portion of the href URL, including the leading question mark (?). Returns an empty string if no query parameters exist. Example ...
Read More