Smita Kapse

Smita Kapse

388 Articles Published

Articles by Smita Kapse

Page 2 of 39

How to set how the last line of a block or a line right before a forced line break is aligned when text-align is "justify" with JavaScript?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 425 Views

The textAlignLast property in JavaScript controls how the last line of a text block is aligned when the text uses text-align: justify. This is particularly useful for controlling the alignment of the final line in justified paragraphs. Syntax element.style.textAlignLast = "value"; Common Values The textAlignLast property accepts these values: auto - Default behavior (usually left-aligned) left - Aligns last line to the left right - Aligns last line to the right center - Centers the last line justify - Justifies the last line (stretches it) Example: Setting Last Line Alignment ...

Read More

Make HTML5 input type="number" accepting dashes

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 3K+ Views

To allow HTML5 input fields to accept dashes along with numbers, you cannot use type="number" directly since it only accepts numeric characters. Instead, use type="text" with a pattern attribute to validate the input format. The Problem with type="number" HTML5 input type="number" strictly accepts only numeric values and will reject any non-numeric characters including dashes. To accept dashes, we need to use type="text" with pattern validation. Solution Using Pattern Attribute Use the pattern attribute with a regular expression to validate numbers with dashes: Number Input with Dashes ...

Read More

How to rotate an image with the canvas HTML5 element from the bottom center angle?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 372 Views

Rotating an image from the bottom center in HTML5 Canvas requires translating the canvas origin to the rotation point, applying the rotation, then drawing the image at an offset position. Understanding Canvas Rotation Canvas rotation always occurs around the origin (0, 0). To rotate from a specific point like bottom center, we must: Translate the canvas to the rotation point Apply the rotation Draw the image at an adjusted position Complete Example const canvas = document.getElementById('myCanvas'); const context = canvas.getContext('2d'); // Create an image const img = new ...

Read More

How to make flexible items display in columns with JavaScript?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 276 Views

The flexFlow property in CSS controls how flexible items are arranged within a flex container. To display items in columns using JavaScript, you can modify this property dynamically. Understanding flexFlow The flexFlow property is a shorthand that combines flex-direction and flex-wrap. For column layout, use column for direction and nowrap or wrap for wrapping behavior. Example Here's how to change flexible items from row to column layout using JavaScript: #box { ...

Read More

How to check web browser support in HTML5

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 314 Views

Checking web browser support for HTML5 features is essential for creating compatible web applications. This guide shows you how to detect HTML5 features using both modern JavaScript methods and the Modernizr library. Using Modernizr Library Modernizr is a popular JavaScript library that detects HTML5 and CSS3 features. Here's how to check for web worker support: Web Worker Support Check function checkWebWorkerSupport(){ ...

Read More

cache.manifest works for the first time then fails in HTML

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 127 Views

HTML5 Application Cache (cache.manifest) can fail after the first load due to caching issues. Here are solutions to ensure proper cache updates. Add NETWORK Section Add the NETWORK section at the bottom of your manifest file to allow network access for unlisted resources: CACHE MANIFEST CACHE: /css/style.css /js/myscript.js /images/logo.png NETWORK: * Version Your Manifest File Include a version parameter in the manifest attribute to force cache updates when content changes: My App Cached Application ...

Read More

What is the usage of oninvalid event in JavaScript?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 337 Views

The oninvalid event is triggered when a form field fails HTML5 validation constraints. It fires before form submission when an field with validation attributes (like required, pattern, etc.) contains invalid data. Syntax element.oninvalid = function() { // Handle invalid input }; // Or in HTML Basic Example Here's how to use oninvalid to show custom validation messages: Enter Name: ...

Read More

How to prevent text select outside HTML5 canvas on double-click?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 394 Views

When users double-click on or near an HTML5 canvas element, browsers may inadvertently select surrounding text. This creates a poor user experience, especially in interactive applications. Here's how to prevent this behavior. The Problem Double-clicking near a canvas element can trigger text selection in surrounding elements, highlighting unwanted text and disrupting the user interface. Solution: Disable Text Selection Set the onselectstart event handler to return false, which prevents the browser from starting text selection on the canvas element. var canvas = document.getElementById('myCanvas'); // Prevent text selection on double-click canvas.onselectstart = ...

Read More

What are JavaScript Identifiers?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 5K+ Views

JavaScript identifiers are names given to variables, functions, classes, objects, and other entities in your code. They work similarly to identifiers in other programming languages like C, C++, and Java, but have specific rules you must follow. What are Identifiers? An identifier is simply a name that you create to reference a variable, function, or other code element. Here are some examples of valid identifiers: // Valid variable identifiers let userName = "John"; let age = 25; let _privateVar = "hidden"; let $element = "jQuery style"; let camelCaseVariable = "standard naming"; console.log(userName); console.log(age); console.log(_privateVar); ...

Read More

How to convert a Unix timestamp to time in JavaScript?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 299 Views

To convert a Unix timestamp to time in JavaScript, you need to multiply the timestamp by 1000 (since Unix timestamps are in seconds, but JavaScript Date expects milliseconds) and then use Date methods to extract time components. What is a Unix Timestamp? A Unix timestamp represents the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. JavaScript's Date constructor expects milliseconds, so we multiply by 1000. Example JavaScript Dates ...

Read More
Showing 11–20 of 388 articles
« Prev 1 2 3 4 5 39 Next »
Advertisements