Javascript Articles

Page 356 of 534

What is the correct use of schema.org SiteNavigationElement in HTML?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 855 Views

The schema.org SiteNavigationElement extends WebPageElement and is used to mark up navigation links on a webpage. It helps search engines understand your site's navigation structure and can enhance search result displays with sitelinks. Basic Syntax The SiteNavigationElement uses microdata attributes to define navigation properties: Link Text Key Properties The main properties used with SiteNavigationElement are: url - The destination URL of the navigation link name - The visible text or name ...

Read More

How to put variable in regular expression match with JavaScript?

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

You can put a variable in a regular expression match by using the RegExp constructor, which accepts variables as patterns. This is essential when you need dynamic pattern matching in JavaScript. Syntax // Using RegExp constructor with variable let pattern = new RegExp(variableName, flags); string.match(pattern); // Or directly with match() string.match(variableName); // for simple string matching Example: Using Variable in Regular Expression let sentence = 'My Name is John'; console.log("The actual value:"); console.log(sentence); let matchWord = 'John'; console.log("The matching value:"); console.log(matchWord); // Using RegExp constructor with variable let matchRegularExpression = ...

Read More

HTML5 Input type=number removes leading zero

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 5K+ Views

HTML5's input type="number" automatically removes leading zeros because it treats the value as a numeric data type. This creates issues when you need to preserve leading zeros, such as for international phone numbers, postal codes, or ID numbers. The Problem When using type="number", browsers strip leading zeros from the input value: Show Value function showValue() { let input = document.getElementById('numberInput'); ...

Read More

Check if a string has white space in JavaScript?

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

To check if a string contains whitespace in JavaScript, you can use several methods. The most common approaches are indexOf(), includes(), and regular expressions. Using indexOf() Method The indexOf() method returns the index of the first whitespace character, or -1 if none is found: function stringHasTheWhiteSpaceOrNot(value){ return value.indexOf(' ') >= 0; } var whiteSpace = stringHasTheWhiteSpaceOrNot("MyNameis John"); if(whiteSpace == true){ console.log("The string has whitespace"); } else { console.log("The string does not have whitespace"); } // Test with different strings console.log(stringHasTheWhiteSpaceOrNot("HelloWorld")); ...

Read More

Raise the Mobile Safari HTML5 application cache limit?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 757 Views

Mobile Safari imposes specific limits on HTML5 application cache storage, unlike desktop Safari which has no strict limits. Understanding these constraints is crucial for mobile web development. Mobile Safari Cache Limits The default application cache limit on mobile Safari is 5MB. This applies to the overall cache storage allocated to your web application. Desktop Safari No Limit Unlimited Cache Mobile Safari 5MB Limit ...

Read More

Formatting text to add new lines in JavaScript and form like a table?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 421 Views

To format text with new lines in JavaScript and create table-like output, use the map() method combined with join(''). The '' character creates line breaks in console output. Syntax array.map(element => `formatted string`).join('') Example: Creating a Table-like Format let studentDetails = [ [101, 'John', 'JavaScript'], [102, 'Bob', 'MySQL'], [103, 'Alice', 'Python'] ]; // Create header let tableHeader = '||Id||Name||Subject||'; // Format data rows let tableRows = studentDetails.map(student => `|${student.join('|')}|` ).join(''); // Combine header ...

Read More

Display video inside HTML5 canvas

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 564 Views

You can display video inside an HTML5 canvas by using the drawImage() method to render video frames onto the canvas. This technique is useful for applying real-time effects, overlays, or custom controls to video content. Basic Setup First, create the HTML structure with both video and canvas elements: Video in Canvas Your browser does not support the video tag. ...

Read More

Creating a JavaScript Object from Single Array and Defining the Key Value?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 194 Views

JavaScript provides several ways to create objects from arrays and define key-value pairs. This is useful when transforming data structures or converting between different formats. Using Object.entries() with map() The most common approach uses Object.entries() to convert an object into an array of key-value pairs, then map() to transform the structure: var studentObject = { 101: "John", 102: "David", 103: "Bob" }; var studentDetails = Object.entries(studentObject).map(([studentId, studentName]) => ({ studentId, studentName })); console.log(studentDetails); ...

Read More

Escaping/encoding single quotes in JSON encoded HTML5 data attributes

George John
George John
Updated on 15-Mar-2026 4K+ Views

When embedding JSON data in HTML5 data attributes, single quotes can break HTML parsing. JavaScript provides several methods to properly escape or encode single quotes to ensure valid HTML output. The Problem with Single Quotes in Data Attributes Single quotes inside JSON values can break HTML attribute parsing when the attribute itself uses single quotes: // Problematic - single quote breaks HTML

Read More

Is it possible to validate the size and type of input=file in HTML5?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 410 Views

Yes, it is possible to validate the size and type of input type="file" in HTML5. You can achieve this using JavaScript to access the File API and check file properties before form submission. HTML5 File Validation Structure The HTML5 File API provides access to file properties like size, type, and name through the files property of the input element. ...

Read More
Showing 3551–3560 of 5,340 articles
« Prev 1 354 355 356 357 358 534 Next »
Advertisements