Javascript Articles

Page 95 of 534

How to create an image to zoom with CSS and JavaScript?

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 1K+ Views

Following is the code to create an image zoom:Example    * {box-sizing: border-box;}    .img{       display: inline-block;    }    .img-zoom-container {       position: relative;    }    .img-zoom-zoomLens {       position: absolute;       border: 1px solid #d4d4d4;       width: 50px;       height: 50px;    }    .myresult{       display: inline-block;    }    .img-zoom-result {       border: 1px solid #d4d4d4;    } Image Zoom Example Hover over the image on the ...

Read More

Smallest possible length constituting greatest frequency in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 194 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.Our function is supposed to find the smallest possible length of a (contiguous) subarray of the array arr, that has the same greatest frequency of any element as the whole array.For example, if the input to the function isInputconst arr = [55, 77, 77, 88, 55];Outputconst output = 2;Output ExplanationThe input array has the greatest frequency for any element of 2 because both elements 55 and 77 appear twice.Of the subarrays that have the greatest frequency as the ...

Read More

How do you make a button that adds text in HTML \'input\'?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

Let’s say the following is our HTML button −Click the button to add the input into the belowText BoxUse document.getElementById() to add a text in on button click. Following is the code −Example Document Click the button to add the input into the below Text Box  document.getElementById("clickButton").addEventListener("click", () =>{ document.getElementById("readTheInput").value += "JavaScript";  }); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output ...

Read More

Enter key press event in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 27K+ Views

For ENTER key press event, you can call a function on −onkeypress=”yourFunctionName”Use the ENTER’s keycode 13.Example Document    function enterKeyPressed(event) {       if (event.keyCode == 13) {          console.log("Enter key is pressed");          return true;       } else {          return false;       }    } To run the above program, save the file name "anyName.html (index.html)" and right click on the file. Select the option "Open with Live Server" in VS Code editor.OutputThis will produce the following output −On pressing ENTER key, the following output is visible on console −

Read More

JavaScript BOM Window Screen

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 515 Views

The JavaScript BOM Window screen contains the information about the client’s screen.The BOM window screen properties are −PropertiesDescriptionscreen.widthReturn the user screen width in pixels.screen.heightReturn the user screen height in pixels.screen.availWidthReturns the user screen width in pixels without taking into account the interface features.screen.availHeightReturns the user screen height in pixels without taking into account the interface features.screen.colorDepthReturns the bits used to display one colorscreen.pixelDepthRetrurns the screen pixel depthFollowing is the code for the JavaScript BOM Window screen −Example Document body {    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result {    font-size: 18px;   ...

Read More

JavaScript function in href vs. onClick

Amit Sharma
Amit Sharma
Updated on 11-Mar-2026 13K+ Views

Both onclick & href have different behaviors when calling JavaScript directly. Also the script in href won’t get executed if the time difference is short. This is for the time between two clicks.ExampleHere’s an example showing the usage of href vs onClick in JavaScript.           JavaScript href vs onClick()              function myFunc() {          var v = 0;          for (var j=0; j

Read More

Add number strings without using conversion library methods in JavaScript

Vivek Verma
Vivek Verma
Updated on 28-Aug-2025 293 Views

We are required to write a JavaScript program that adds two numbers represented as strings, without using any conversion library or built-in methods. For example, If the input number strings are '11' and '23', the output should be '34'. In JavaScript, a number is considered a string-represented number when the number is enclosed in single quotes ('number') or double quotes ("number"). For example: '123' or "456". If you use the typeof operator on such values, it will return the type as 'string'. Here are a few input and output scenarios that provide a better understanding of the given problem: Scenario ...

Read More

Add elements to a Queue using Javascript

Vivek Verma
Vivek Verma
Updated on 28-Aug-2025 493 Views

In JavaScript, there is no such data structure concept as a Queue like other programming languages. But you can implement a queue in JavaScript using an array object. You can perform all the operations such as push() method to add element at end and shift() to remove first element. The following diagram will give a clear understanding of the queue data structure and its principles (FIFO): A Queue is a linear data structure that follows the FIFO (First In, First Out) principle. In JavaScript, it is used to store and manage elements of similar or different types. Here is ...

Read More

Adding default search text to search box in HTML with JavaScript?

Vivek Verma
Vivek Verma
Updated on 28-Aug-2025 595 Views

A default search text is a text that provides suggestions or a hint of what to search for in the search (input) box. Following is an illustration of a search box, where you can observe a default search text "Search your favorite tutorials…" : The above default search text will suggest to visitors that they can search for their favorite tutorial, which they want to read or open on the website. Adding Default Search Text to Search Box Using JavaScript In HTML, the text (i.e., search text) that appears inside a search box or input field before the user ...

Read More

Achieving maximum possible pair sum in JavaScript

Vivek Verma
Vivek Verma
Updated on 28-Aug-2025 273 Views

Maximum Possible Pair Sum The maximum possible pair sum is a traditional problem in Data Structures and Algorithms (DSA). In this problem, we calculate the sum of two elements (i.e., pairs) in an array such that the resulting sum is the maximum among all possible pair sums. For example, we have an array [1, 2, 3, 4]. The sum of the pair (3, 4) is 7, which is the maximum among all pair sums in the given array. Problem Statement We have given an array named nums[], and our task is to write a JavaScript program to achieve the maximum ...

Read More
Showing 941–950 of 5,338 articles
« Prev 1 93 94 95 96 97 534 Next »
Advertisements