Object Oriented Programming Articles

Page 97 of 589

How to create a draggable HTML element with JavaScript and CSS?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 748 Views

To create a draggable HTML element with JavaScript and CSS, you need to handle mouse events and update the element's position dynamically. This technique allows users to click and drag elements around the page. Basic HTML Structure Start with an HTML element that has absolute positioning and a move cursor to indicate it's draggable: body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .dragDiv { position: absolute; ...

Read More

How to use media queries with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 401 Views

JavaScript provides the window.matchMedia() method to detect and respond to CSS media query changes dynamically. This allows you to create responsive behavior that adapts to screen size, device orientation, and other media features. Basic Syntax let mediaQuery = window.matchMedia("(max-width: 768px)"); // Check if query matches if (mediaQuery.matches) { // Screen is 768px or smaller } // Listen for changes mediaQuery.addEventListener('change', function(e) { if (e.matches) { // Query now matches } }); Example: Responsive ...

Read More

How to create and use a Syntax Highlighter with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 361 Views

A syntax highlighter in JavaScript allows you to apply styling to specific code elements like keywords, strings, or HTML tags. This tutorial shows how to create a basic highlighter using regular expressions and DOM manipulation. Example: HTML Link Highlighter This example highlights HTML anchor tags by applying custom CSS styles: body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .colorLinks { color: rgb(131, 44, 212); ...

Read More

How to create a weight converter with HTML and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 466 Views

Creating a weight converter with HTML and JavaScript involves building a simple form that takes weight input in one unit and converts it to another unit in real-time. This tutorial demonstrates how to create a kilogram to gram converter. HTML Structure The HTML provides the basic structure with an input field for kilograms and a display area for the converted grams: body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } input, span{ ...

Read More

How to create a temperature converter with HTML and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 842 Views

To create a temperature converter with HTML and JavaScript, you need to combine form elements with JavaScript functions to perform real-time temperature conversions. Complete Temperature Converter Example body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; } .converter-container { background: #f8f9fa; border-radius: ...

Read More

How to create a length converter with HTML and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

To create a length converter with HTML and JavaScript, you'll need to combine HTML form elements with JavaScript functions to handle the conversion logic. This tutorial demonstrates building a simple kilometer-to-meter converter. HTML Structure The converter uses an input field for kilometers and displays the converted meters value. The oninput and onchange events trigger the conversion function automatically as you type. Complete Example body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; padding: 20px; ...

Read More

How to create a speed converter with HTML and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 384 Views

To create a speed converter with HTML and JavaScript, we'll build a simple web application that converts kilometers per hour to meters per second. This involves HTML for the interface and JavaScript for the conversion logic. HTML Structure The HTML creates the user interface with an input field for entering speed values and a display area for the converted result: body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; padding: 20px; ...

Read More

How to output JavaScript into a Textbox?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 5K+ Views

You can output JavaScript values to a textbox using the value property. This is commonly done to display calculation results or user feedback. Basic Approach To output to a textbox, access the input element and set its value property: document.getElementById("myTextbox").value = "Your output here"; Example: Calculator with Textbox Output JavaScript Textbox Output First Number: ...

Read More

Explain JavaScript text alert

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 261 Views

The JavaScript alert() function is used to display a popup message to the user. It's a built-in browser method that creates a modal dialog box with a message and an "OK" button. Syntax alert(message); Parameters The alert() function accepts one parameter: message - A string that specifies the text to display in the alert box Basic Example JavaScript Alert Example JavaScript Text ...

Read More

Flat a JavaScript array of objects into an object

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

To flatten a JavaScript array of objects into a single object, we can create a function that iterates through each object in the array and combines their properties. This technique is useful when you need to merge multiple objects while preserving unique property names by appending indices. Basic Approach The most straightforward method is to loop through the array and create new property names by appending the array index to each original property name. // Example array of objects const notes = [{ title: 'Hello world', id: 1 ...

Read More
Showing 961–970 of 5,881 articles
« Prev 1 95 96 97 98 99 589 Next »
Advertisements