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 Jennifer Nicholas
Page 4 of 21
What are different Navigator methods available?
The Navigator object provides several methods to interact with the browser and detect client capabilities. Here are the main Navigator methods available in JavaScript: Navigator Methods Overview Method Description Browser Support ...
Read MoreHow to convert PHP array to JavaScript array?
Converting PHP arrays to JavaScript arrays is essential when passing server-side data to client-side scripts. PHP's json_encode() function provides a reliable way to achieve this conversion for both single and multidimensional arrays. Syntax // PHP side $phpArray = array('value1', 'value2'); // JavaScript side var jsArray = ; Example: Converting Simple PHP Array Let's start with a simple PHP array containing user information: var arr = ; console.log(arr); // Output: ["Amit", "amit@example.com"] console.log(arr[0]); // Output: "Amit" ...
Read MoreWhat is the role of throw statement in JavaScript?
The throw statement in JavaScript is used to manually create and raise exceptions. When executed, it stops the normal execution flow and passes control to the nearest catch block. Syntax throw expression; The expression can be any value: string, number, boolean, object, or Error instance. Basic Example Here's how to use throw with a simple string message: function checkDivision() { var a = 100; ...
Read MoreHow to search the value of the type attribute of a link in JavaScript?
To search or retrieve the value of the type attribute of a link in JavaScript, you can use the type property of the anchor element. This attribute specifies the MIME type of the linked resource. Syntax element.type Example: Getting Type Attribute Value Qries var x = document.getElementById("qriesid").type; document.write("Value of the type attribute: " + x); ...
Read MoreHow to calculate the difference between two dates in JavaScript?
To calculate the difference between two dates in JavaScript, use the getTime() method to get timestamps in milliseconds, then subtract one from the other. Basic Date Difference Calculation The getTime() method returns the number of milliseconds since January 1, 1970. By subtracting two timestamps, you get the difference in milliseconds. var dateFirst = new Date("11/25/2017"); var dateSecond = new Date("11/28/2017"); // time difference in milliseconds var timeDiff = Math.abs(dateSecond.getTime() - dateFirst.getTime()); // days difference var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); // display result console.log("Difference: " ...
Read MoreHTML5 / JS storage event handler
Storage event handlers in HTML5 only fire when storage changes are triggered by another window or tab. This means storage events won't fire in the same window that made the change. Syntax window.addEventListener('storage', function(event) { // Handle storage changes from other windows }, false); Example: Basic Storage Event Handler Storage Event Example Storage Event Demo Open this page in another tab and click the button to see the event fire. ...
Read MoreWhat is the best way to break from nested loops in JavaScript?
The best way to break from nested loops in JavaScript is to use labels. A label is an identifier followed by a colon (:) that allows you to control loop flow more precisely with break and continue statements. Syntax labelName: for (let i = 0; i < n; i++) { for (let j = 0; j < m; j++) { if (condition) break labelName; // Breaks outer loop } } Example: Breaking from Nested Loops ...
Read MoreSet a rounded active and hover button with CSS
The CSS :hover pseudo-class allows you to add interactive effects when users hover over elements, while the border-radius property creates rounded corners. Combining these with the .active class creates visually appealing navigation buttons with distinct states. Syntax /* Hover effect */ selector:hover { property: value; } /* Active state */ selector.active { property: value; } /* Rounded corners */ selector { border-radius: value; } Example: Rounded Active and Hover Buttons The following example creates a navigation menu with rounded buttons ...
Read MoreAdd space between pagination links with CSS
Pagination links often appear too close together by default. Adding space between pagination links improves readability and provides better visual separation. This can be achieved using CSS properties like margin, padding, or gap. Syntax /* Method 1: Using margin */ .pagination a { margin: value; } /* Method 2: Using gap (for flex/grid containers) */ .pagination { display: flex; gap: value; } Method 1: Using Margin The following example adds space between pagination links using the margin property − ...
Read MoreFlip an image on mouse over with CSS
The CSS transform property can be used to flip an image horizontally when a user hovers over it. This creates an engaging interactive effect by using the scaleX(-1) value to mirror the image along its X-axis. Syntax selector:hover { transform: scaleX(-1); } Example: Horizontal Image Flip on Hover The following example demonstrates how to flip an image horizontally when the mouse hovers over it − .flip-image { width: 300px; ...
Read More